iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 1 | module TChannelTransport(TChannelTrans(..)) where |
| 2 | import System.IO |
| 3 | import IO |
| 4 | import Thrift |
| 5 | import Control.Exception |
| 6 | data TChannelTrans = TChannelTrans (Handle) |
| 7 | |
| 8 | instance TTransport TChannelTrans where |
| 9 | tisOpen a = True |
| 10 | topen a = return a |
| 11 | tclose a = return a |
| 12 | tread a 0 = return [] |
David Reiss | 0c90f6f | 2008-02-06 22:18:40 +0000 | [diff] [blame] | 13 | tread (TChannelTrans h) i = Prelude.catch |
iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 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 | |