Safe Haskell | None |
---|
LogicGrowsOnTrees.Utils.Handle
Contents
Description
This module contains a couple of utility functions for sending and receiving
Serialize
-able data over a handle. Because the size of the serialized
value can depend on the value being sent, these functions employ a protocol
in which first the size of the serialized data is sent as a 64-bit
big-endian word, and then the serialized data itself is sent.
- data ConnectionLost = ConnectionLost
- filterEOFExceptions :: IO a -> IO a
- receive :: Serialize α => Handle -> IO α
- send :: Serialize α => Handle -> α -> IO ()
Exceptions
data ConnectionLost Source
This exception is thrown when the connection has been lost.
Constructors
ConnectionLost |
Functions
filterEOFExceptions :: IO a -> IO aSource
Replaces EOF IOException
s with the ConnectionLost
exception.
receive :: Serialize α => Handle -> IO αSource
Receives a Serialize
-able value from a handle.
Specifically, this function reads in a 64-bit big-endian word with the
size of the raw data to be read, reads that much data in bytes into a
ByteString
, and then deserializes the ByteString
to produce the
resulting value.
If the connection has been lost, it throws ConnectionLost
.
send :: Serialize α => Handle -> α -> IO ()Source
Sends a Serialize
-able value to a handle.
Specifically, this function serializes the given value to a ByteString
,
and then writes the size of the serialized data in bytes as a 64-bit
big-endian word followed by the raw data itself.
If the connection has been lost, it throws ConnectionLost
.