Portability | portable |
---|---|
Stability | provisional |
Maintainer | gcrosswhite@gmail.com |
Monad to ease writing a binary network protocol.
- type BinaryProtocol = StateT (Handle, Handle, ByteString) IO
- runProtocol :: BinaryProtocol a -> Handle -> Handle -> IO a
- receive :: Binary a => BinaryProtocol a
- send :: Binary a => a -> BinaryProtocol ()
- flush :: BinaryProtocol ()
Documentation
type BinaryProtocol = StateT (Handle, Handle, ByteString) IOSource
runProtocol :: BinaryProtocol a -> Handle -> Handle -> IO aSource
Take a BinaryProtocol monad and run it on the given handles for respectively reading and writing. (The two given handles are allowed to be the same if the same handle is used for reading and writing.)
Note: We run L.hGetContents on the read handle, so don't expect to be able to use it after you have called this function.
receive :: Binary a => BinaryProtocol aSource
Read in a value of type a
from the connection; a
must be an
instance of the Binary
class.
send :: Binary a => a -> BinaryProtocol ()Source
Send a value of type a
down the connection; a
must be an
instance of the Binary
class.
flush :: BinaryProtocol ()Source
Flush buffered send data down the connection.
Note: You need to make sure to call this between sending requests and receiving responses in order to ensure that the request has actually been sent down the connection; otherwise you might get stuck waiting for a response that will not come.