Safe Haskell | None |
---|---|
Language | Haskell98 |
Synopsis
- socketReader :: MonadIO m => Socket -> Producer ByteString m ()
- socketWriter :: MonadIO m => Socket -> Consumer ByteString m ()
- type Handler r = Producer ByteString IO () -> Consumer ByteString IO () -> IO r
- runSocketServer :: MonadIO m => Socket -> Handler () -> m ()
- runSocketClient :: MonadIO m => Socket -> Handler r -> m r
Socket pipes
socketReader :: MonadIO m => Socket -> Producer ByteString m () Source #
Stream data from the socket.
socketWriter :: MonadIO m => Socket -> Consumer ByteString m () Source #
Stream data to the socket.
Socket server/client
type Handler r = Producer ByteString IO () -> Consumer ByteString IO () -> IO r Source #
A simple handler: takes an incoming stream of ByteString
s, an
stream of ByteString
s, and ties them together somehow.
Conceptually, the simplest handler would be identity
:
import Control.Monad import Control.Pipe import Data.ByteString.Char8 handler reader writer = do let identity = forever $ do x <- await yield x runPipe (writer <+< identity <+< reader)
See the pipes
tutorial for more examples of writing pipes.
Since ByteString
s are fairly boring by themseleves, have a look
at Control.Pipe.Serialize which lets you deserialize/serialize
pipes of ByteString
s easily.
runSocketServer :: MonadIO m => Socket -> Handler () -> m () Source #
Listen for connections on the given socket, and run Handler
on
each received connection. The socket should previously have been
bound to a port or to a file. Each handler is run in its own
thread. Even in case of an error, the handlers' sockets are
closed.