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

Safe HaskellNone

Control.Proxy.TCP.Safe.Sync

Contents

Description

This module exports Proxys that allow implementing synchronous RPC-like communication with a remote end by using a simple protocol on their downstream interface.

As opposed to the similar proxies found in Control.Proxy.TCP.Sync, these use the exception handling facilities provided by ExceptionP.

You may prefer the more general proxies from Control.Proxy.TCP.Safe.

Synopsis

Socket proxies

socketSyncServerSource

Arguments

:: Proxy p 
=> Maybe Int

Optional timeout in microseconds (1/10^6 seconds).

-> Socket

Connected socket.

-> Request ByteString 
-> Server (ExceptionP p) (Request ByteString) Response SafeIO () 

Server able to send and receive bytes through a Socket.

If downstream requests Send bytes, then such bytes are sent to the remote end and then this proxy responds Sent downstream.

If downstream requests Receive num, then at most num bytes are received from the remote end. This proxy then responds downstream such received bytes as Received bytes. Less than the specified maximum number of bytes might be received at once.

If an optional timeout is given and interactions with the remote end take more time that such timeout, then throw a Timeout exception in the ExceptionP proxy transformer.

If the remote peer closes its side of the connection, this proxy returns.

socketSyncProxySource

Arguments

:: Proxy p 
=> Maybe Int

Optional timeout in microseconds (1/10^6 seconds).

-> Socket

Connected socket.

-> Request a' 
-> ExceptionP p a' ByteString (Request a') Response SafeIO () 

Proxy able to send and receive bytes through a Socket.

If downstream requests Send a', then such a' request is forwarded upstream, which in return responds a ByteString that this proxy sends to the remote end. After sending to the remote end, this proxy responds Sent downstream.

If downstream requests Receive num, then at most num bytes are received from the remote end. This proxy then responds downstream such received bytes as Received bytes. Less than the specified maximum number of bytes might be received at once.

If an optional timeout is given and interactions with the remote end take more time that such timeout, then throw a Timeout exception in the ExceptionP proxy transformer.

If the remote peer closes its side of the connection, this proxy returns.

RPC support

syncDelimitSource

Arguments

:: (Monad m, Proxy p) 
=> Int

Maximum number of bytes to receive at once.

-> ByteString

Delimiting bytes.

-> b' 
-> p (Request b') Response b' ByteString m r 

When used together with one of the socketSync* proxies upstream, this proxy sends a single ByteString to the remote end and then repeatedly receives bytes from the remote end until the given delimiter is found. Finally, a single ByteString up to the given delimiter (inclusive) is sent downstream and then the whole process is repeated.

This proxy works cooperatively with any socketSync* proxy immediately upstream, so read their documentation to understand the purpose of the b' value received from downstream.

For example, if you'd like to convert a Socket into an synchronous line-oriented RPC client implemented as a Server in which RPC calls are received via the downstream interface and RPC responses are sent downstream, then you could use this proxy as:

 socketSyncServer ... >-> syncDelimit 4096 "\r\n"

Otherwise, if you'd like to convert a Socket into an synchronous line-oriented RPC client implemented as a Proxy in which RPC calls are received via the upstream interface and RPC responses are sent downstream, then you could use this proxy as:

 socketSyncProxy ... >-> syncDelimit 4096 "\r\n"

Protocol

data Request t Source

A request made to one of the socketSync* proxies.

Constructors

Send t 
Receive Int 

Instances

Eq t => Eq (Request t) 
Read t => Read (Request t) 
Show t => Show (Request t) 

data Response Source

A response received from one of the socketSync* proxies.

Constructors

Sent 
Received ByteString