blob: bf2e8a6aa02f6a4cca0c17e0700e7207fcd753d4 [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 []
David Reiss0c90f6f2008-02-06 22:18:40 +000013 tread (TChannelTrans h) i = Prelude.catch
iproctorff8eb922007-07-25 19:06:13 +000014 (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