pipes-network-0.6.4.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

Synopsis

Receiving

The following producers allow you to receive bytes from the remote end.

Besides the producers 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 #

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

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 (1 second = 1e6 microseconds).

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

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

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 (1 second = 1e6 microseconds).

Sending

The following consumers allow you to send bytes to the remote end.

Besides the consumers below, you might want to use Network.Simple.TCP's send, sendLazy or sendMany which happen to be Effect's:

send     :: MonadIO m => Socket ->  ByteString  -> Effect' m ()
sendLazy :: MonadIO m => Socket ->  ByteString  -> Effect' m ()
sendMany :: MonadIO m => Socket -> [ByteString] -> Effect' m ()

toSocket #

Arguments

:: MonadIO m 
=> Socket

Connected socket.

-> Consumer' ByteString m r 

Sends to the remote end each ByteString received from upstream.

toSocketLazy #

Arguments

:: MonadIO m 
=> Socket

Connected socket.

-> Consumer' ByteString m r 

Like toSocket but takes a lazy ByteSring and sends it in a more efficient manner (compared to converting it to a strict ByteString and sending it).

toSocketMany #

Arguments

:: MonadIO m 
=> Socket

Connected socket.

-> Consumer' [ByteString] m r 

Like toSocket but takes a [ByteSring] and sends it in a more efficient manner (compared to converting it to a strict ByteString and sending it).

toSocketTimeout :: MonadIO m => Int -> Socket -> Consumer' ByteString m r #

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 (1 second = 1e6 microseconds).

toSocketTimeoutLazy :: MonadIO m => Int -> Socket -> Consumer' ByteString m r #

Like toSocketTimeout but takes a lazy ByteSring and sends it in a more efficient manner (compared to converting it to a strict ByteString and sending it).

toSocketTimeoutMany :: MonadIO m => Int -> Socket -> Consumer' [ByteString] m r #

Like toSocketTimeout but takes a [ByteSring] and sends it in a more efficient manner (compared to converting it to a strict ByteString and sending it).

Exports