Safe Haskell | None |
---|---|
Language | Haskell2010 |
- class Transport t where
- send :: t -> ByteString -> IO ()
- recv :: t -> Int -> IO ByteString
- recvExactly :: Transport t => t -> Int -> IO ByteString
- data Socket :: *
- withConnection :: ByteString -> Int -> (Socket -> IO a) -> IO a
- connect :: ByteString -> Int -> IO Socket
- close :: Socket -> IO ()
Documentation
class Transport t where Source
Types that provide a means to send and receive bytes.
send :: t -> ByteString -> IO () Source
Send the given ByteString down the transport.
This must block until the request has been finished.
recv :: t -> Int -> IO ByteString Source
Read up to the given number of bytes from the stream.
The returned ByteString may be empty if the end of the stream was reached.
recvExactly :: Transport t => t -> Int -> IO ByteString Source
Keep reading from the given transport until the given number of bytes are read or the end of the stream is reached -- whichever comes first.
data Socket :: *
Represents a socket. The fields are, respectively:
- File descriptor
- Socket family
- Socket type
- Protocol number
- Status flag
If you are calling the MkSocket
constructor directly you should ensure
you have called withSocketsDo
.
withConnection :: ByteString -> Int -> (Socket -> IO a) -> IO a Source
Open a connection, execute the given operation on it, and ensure it is closed afterwards even if an exception was thrown.
withConnection "localhost" 9092 $ \conn -> doStuff conn fail "something went wrong"
Throws an IOException
if we were unable to open the connection.
connect :: ByteString -> Int -> IO Socket Source
Create a new connection.
Connects to the given hostname and port. Throws an IOException
in case
of failure.