| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Data.Connection
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:
InputStreamis choosen to simplify streaming processing. You can easily push back some data withunRead, readingInputStreamwill block until GHC IO manager find data is ready, for example:will block until at least 1024 bytes are available.readExactly1024- 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() connExtraInfofield store extra data about the connection,SockAddrfor example. You can also use this field as a type tag to distinguish different type of connection.closeshould close connection resource, thus theConnectionshouldn't be used anymore aftercloseis called.- You should make sure there's no pending recv/send before you
closeaConnection. That means either you callclosein the same thread you recv/send, or use async exception to terminate recv/send thread before callclosein 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
closewithbracketto ensure safety.
Since: 1.0
Constructors
| Connection | |
Fields
| |