pipes-network-0.6.1: Use network sockets together with the pipes library.

Safe HaskellNone
LanguageHaskell98

Pipes.Network.TCP

Contents

Description

This minimal module exports facilities that ease the usage of TCP Sockets 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 Sockets 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.

Synopsis

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)

fromSocket Source

Arguments

:: 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 4096 if you don't care.

-> 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 ()

toSocket Source

Arguments

:: 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

Like toSocket, 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).

Exports