blob: df1aedc39a450f785ad12befcfc561d28ca83be5 [file] [log] [blame]
iproctorff8eb922007-07-25 19:06:13 +00001module TChannelTransport(TChannelTrans(..)) where
2import System.IO
3import IO
4import Thrift
5import Control.Exception
6data TChannelTrans = TChannelTrans (Handle)
7
8instance TTransport TChannelTrans where
9 tisOpen a = True
10 topen a = return a
11 tclose a = return a
12 tread a 0 = return []
13 tread (TChannelTrans h) i = Prelude.catch
14 (do c <- hGetChar h
15 t <- tread (TChannelTrans h) (i-1)
16 return $ c:t)
17 (\e -> if isEOFError e then return [] else throwDyn (TransportExn "TChannelTransport: Could not read" TE_UNKNOWN))
18 twrite a [] = return ()
19 twrite (TChannelTrans h) (c:t) = do hPutChar h c
20 twrite (TChannelTrans h) t
21 tflush (TChannelTrans h) = hFlush h
22