Thrift: Haskell library and codegen
Summary: It's thrift for haskell. The codegen is complete. The library has binary protocol, io channel transport, and a threaded server.
Reviewed by: mcslee
Test plan: Yes
Revert plan: yes
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665174 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/hs/src/TSocket.hs b/lib/hs/src/TSocket.hs
new file mode 100644
index 0000000..7e72878
--- /dev/null
+++ b/lib/hs/src/TSocket.hs
@@ -0,0 +1,33 @@
+module TSocket(TSocket(..)) where
+import Thrift
+import Data.IORef
+import Network
+import IO
+import Control.Exception
+data TSocket = TSocket{host::[Char],port::PortNumber,chan :: Maybe Handle}
+
+instance TTransport TSocket where
+ tisOpen a = case chan a of
+ Just _ -> True
+ Nothing -> False
+ topen a = do h <- connectTo (host a) (PortNumber (port a))
+ return $ (a{chan = Just h})
+ tclose a = case chan a of
+ Just h -> do hClose h
+ return $ a{chan=Nothing}
+ Nothing -> return a
+ tread a 0 = return []
+ tread a n = case chan a of
+ Just h -> handle (\e -> throwDyn (TransportExn "TSocket: Could not read." TE_UNKNOWN))
+ (do c <- hGetChar h
+ l <- tread a (n-1)
+ return $ c:l)
+ Nothing -> return []
+ twrite a s = case chan a of
+ Just h -> hPutStr h s
+ Nothing -> return ()
+ tflush a = case chan a of
+ Just h -> hFlush h
+ Nothing -> return ()
+
+