Safe Haskell | None |
---|
This module exports Proxy
s 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.
- socketSyncServer :: Proxy p => Maybe Int -> Socket -> Request ByteString -> Server (ExceptionP p) (Request ByteString) Response SafeIO ()
- socketSyncProxy :: Proxy p => Maybe Int -> Socket -> Request a' -> ExceptionP p a' ByteString (Request a') Response SafeIO ()
- syncDelimit :: (Monad m, Proxy p) => Int -> ByteString -> b' -> p (Request b') Response b' ByteString m r
- data Request t
- data Response
- = Sent
- | Received ByteString
Socket proxies
:: 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
, then such Send
bytesbytes
are sent to the
remote end and then this proxy responds Sent
downstream.
If downstream requests
, then at most Receive
numnum
bytes are received
from the remote end. This proxy then responds downstream such received
bytes as
. Less than the specified maximum number of bytes
might be received at once.
Received
bytes
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.
:: 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
, then such Send
a'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
, then at most Receive
numnum
bytes are received
from the remote end. This proxy then responds downstream such received
bytes as
. Less than the specified maximum number of bytes
might be received at once.
Received
bytes
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
:: (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
A request made to one of the socketSync*
proxies.