Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data Connection a = Connection {
- source :: !(InputStream ByteString)
- send :: ByteString -> IO ()
- close :: IO ()
- connExtraInfo :: a
Documentation
data Connection a Source #
A simple connection abstraction.
Connection
s from this package are supposed to have following properties:
InputStream
is choosen to simplify streaming processing. You can easily push back some data withunRead
, readingInputStream
will block until GHC IO manager find data is ready, for example:
will block until at least 1024 bytes are available.readExactly
1024- The type
is choosen because it worked well with haskell's builder infrastructure. vector-IO is used automatically when there's more than one chunk to send to save system call.ByteString
->IO
() connExtraInfo
field store extra data about the connection,SockAddr
for example. You can also use this field as a type tag to distinguish different type of connection.close
should close connection resource, thus theConnection
shouldn't be used anymore afterclose
is called.- You should make sure there's no pending recv/send before you
close
aConnection
. That means either you callclose
in the same thread you recv/send, or use async exception to terminate recv/send thread before callclose
in other thread(such as a reaper thread). Otherwise you may run into race-connections. - Exception or closed by other peer during recv/send will NOT close underline socket,
you should always use
close
withbracket
to ensure safety.
Since: 1.0
Connection | |
|