Safe Haskell | None |
---|---|
Language | Haskell98 |
This minimal module exports facilities that ease the usage of TCP
Socket
s in the Pipes ecosystem. It is meant to be used together with
the Network.Simple.TCP module from the network-simple
package, which is
completely re-exported from this module.
This module does not export facilities that would allow you to acquire new
Socket
s within a pipeline. If you need to do so, then you should use
Pipes.Network.TCP.Safe instead, which exports a similar API to the one
exported by this module. However, don't be confused by the word “safe” in
that module; this module is equally safe to use as long as you don't try to
acquire resources within the pipeline.
- fromSocket :: MonadIO m => Socket -> Int -> Producer' ByteString m ()
- fromSocketTimeout :: MonadIO m => Int -> Socket -> Int -> Producer' ByteString m ()
- fromSocketN :: MonadIO m => Socket -> Int -> Server' Int ByteString m ()
- fromSocketTimeoutN :: MonadIO m => Int -> Socket -> Int -> Server' Int ByteString m ()
- toSocket :: MonadIO m => Socket -> Consumer' ByteString m r
- toSocketTimeout :: MonadIO m => Int -> Socket -> Consumer' ByteString m r
- module Network.Simple.TCP
Receiving
The following pipes allow you to receive bytes from the remote end.
Besides the pipes below, you might want to use Network.Simple.TCP's
recv
, which happens to be an Effect'
:
recv
::MonadIO
m =>Socket
->Int
->Effect'
m (Maybe
ByteString
)
:: MonadIO m | |
=> Socket | Connected socket. |
-> Int | Maximum number of bytes to receive and send
dowstream at once. Any positive value is fine, the
optimal value depends on how you deal with the
received data. Try using |
-> Producer' ByteString m () |
Receives bytes from the remote end and sends them downstream.
The number of bytes received at once is always in the interval [1 .. specified maximum].
This Producer'
returns if the remote peer closes its side of the connection
or EOF is received.
fromSocketTimeout :: MonadIO m => Int -> Socket -> Int -> Producer' ByteString m () Source
Like fromSocket
, except with the first Int
argument you can specify
the maximum time that each interaction with the remote end can take. If such
time elapses before the interaction finishes, then an IOError
exception is
thrown. The time is specified in microseconds (10e6).
Bidirectional pipes
The following pipes are bidirectional, which means useful data can flow through them upstream and downstream. If you don't care about bidirectional pipes, just skip this section.
fromSocketN :: MonadIO m => Socket -> Int -> Server' Int ByteString m () Source
Like fromSocket
, except the downstream pipe can specify the maximum
number of bytes to receive at once using request
.
fromSocketTimeoutN :: MonadIO m => Int -> Socket -> Int -> Server' Int ByteString m () Source
Like fromSocketN
, except with the first Int
argument you can specify
the maximum time that each interaction with the remote end can take. If such
time elapses before the interaction finishes, then an IOError
exception is
thrown. The time is specified in microseconds (10e6).
Sending
The following pipes allow you to send bytes to the remote end.
Besides the pipes below, you might want to use Network.Simple.TCP's
send
, which happens to be an Effect'
:
send
::MonadIO
m =>Socket
->ByteString
->Effect'
m ()
:: MonadIO m | |
=> Socket | Connected socket. |
-> Consumer' ByteString m r |
Sends to the remote end each ByteString
received from upstream.
toSocketTimeout :: MonadIO m => Int -> Socket -> Consumer' ByteString m r Source
Exports
module Network.Simple.TCP