Portability | non-portable |
---|---|
Stability | experimental |
Maintainer | toralf.wittner@gmail.com |
0MQ haskell binding. The API closely follows the C-API of 0MQ with the main difference that sockets are typed. The documentation of the individual socket types is copied from 0MQ's man pages authored by Martin Sustrik. For details please refer to http:api.zeromq.org
- type Size = Word
- data Context
- data Socket a
- data Flag
- data SocketOption
- data Poll
- type Timeout = Int64
- data PollEvent
- class SType a
- class SubsType a
- data Pair = Pair
- data Pub = Pub
- data Sub = Sub
- data Req = Req
- data Rep = Rep
- data XReq = XReq
- data XRep = XRep
- data Pull = Pull
- data Push = Push
- data Up = Up
- data Down = Down
- withContext :: Size -> (Context -> IO a) -> IO a
- withSocket :: SType a => Context -> a -> (Socket a -> IO b) -> IO b
- setOption :: Socket a -> SocketOption -> IO ()
- getOption :: Socket a -> SocketOption -> IO SocketOption
- subscribe :: SubsType a => Socket a -> String -> IO ()
- unsubscribe :: SubsType a => Socket a -> String -> IO ()
- bind :: Socket a -> String -> IO ()
- connect :: Socket a -> String -> IO ()
- send :: Socket a -> ByteString -> [Flag] -> IO ()
- send' :: Socket a -> ByteString -> [Flag] -> IO ()
- receive :: Socket a -> [Flag] -> IO ByteString
- moreToReceive :: Socket a -> IO Bool
- poll :: [Poll] -> Timeout -> IO [Poll]
- version :: IO (Int, Int, Int)
- init :: Size -> IO Context
- term :: Context -> IO ()
- socket :: SType a => Context -> a -> IO (Socket a)
- close :: Socket a -> IO ()
- data Device
- device :: Device -> Socket a -> Socket b -> IO ()
Documentation
Flags to apply on send operations (cf. man zmq_send)
NoBlock
- Send operation should be performed in non-blocking mode. If it cannot be performed immediatley an error will be thrown (errno is set to EAGAIN).
data SocketOption Source
The option to set on 0MQ sockets (cf. zmq_setsockopt and zmq_getsockopt manpages for details).
Affinity Word64 | ZMQ_AFFINITY |
Backlog CInt | ZMQ_BACKLOG |
Events PollEvent | ZMQ_EVENTS |
FD CInt | ZMQ_FD |
Identity String | ZMQ_IDENTITY |
Linger CInt | ZMQ_LINGER |
Rate Int64 | ZMQ_RATE |
ReceiveBuf Word64 | ZMQ_RCVBUF |
ReceiveMore Bool | ZMQ_RCVMORE |
ReconnectIVL CInt | ZMQ_RECONNECT_IVL |
ReconnectIVLMax CInt | ZMQ_RECONNECT_IVL_MAX |
RecoveryIVL Int64 | ZMQ_RECOVERY_IVL |
SendBuf Word64 | ZMQ_SNDBUF |
HighWM Word64 | ZMQ_HWM |
McastLoop Bool | ZMQ_MCAST_LOOP |
RecoveryIVLMsec Int64 | ZMQ_RECOVERY_IVL_MSEC |
Swap Int64 | ZMQ_SWAP |
Type representing a descriptor, poll is waiting for (either a 0MQ socket or a file descriptor) plus the type of event to wait for.
The events to wait for in poll (cf. man zmq_poll)
Socket types.
Socket to communicate with a single peer. Allows for only a
single connect or a single bind. There's no message routing
or message filtering involved. Compatible peer sockets: Pair
.
Socket to send requests and receive replies. Requests are
load-balanced among all the peers. This socket type allows only an
alternated sequence of send's and recv's.
Compatible peer sockets: Rep
, Xrep
.
Special socket type to be used in request/reply middleboxes
such as zmq_queue(7). Requests forwarded using this socket type
should be tagged by a proper prefix identifying the original requester.
Replies received by this socket are tagged with a proper postfix
that can be use to route the reply back to the original requester.
Compatible peer sockets: Rep
, Xrep
.
Special socket type to be used in request/reply middleboxes
such as zmq_queue(7). Requests received using this socket are already
properly tagged with prefix identifying the original requester. When
sending a reply via XREP socket the message should be tagged with a
prefix from a corresponding request.
Compatible peer sockets: Req
, Xreq
.
A socket of type Pull is used by a pipeline node to receive messages from upstream pipeline nodes. Messages are fair-queued from among all connected upstream nodes. The zmq_send() function is not implemented for this socket type.
A socket of type Push is used by a pipeline node to send messages to downstream pipeline nodes. Messages are load-balanced to all connected downstream nodes. The zmq_recv() function is not implemented for this socket type.
When a Push socket enters an exceptional state due to having reached the high water mark for all downstream nodes, or if there are no downstream nodes at all, then any zmq_send(3) operations on the socket shall block until the exceptional state ends or at least one downstream node becomes available for sending; messages are not discarded.
Socket to receive messages from up the stream. Messages are
fair-queued from among all the connected peers. Send function is not
implemented for this socket type. Compatible peer sockets: Down
.
Socket to send messages down stream. Messages are load-balanced
among all the connected peers. Send function is not implemented for
this socket type. Compatible peer sockets: Up
.
withContext :: Size -> (Context -> IO a) -> IO aSource
Run an action with a 0MQ context. The Context
supplied to your
action will not be valid after the action either returns or
throws an exception.
withSocket :: SType a => Context -> a -> (Socket a -> IO b) -> IO bSource
Run an action with a 0MQ socket. The socket will be closed after running the supplied action even if an error occurs. The socket supplied to your action will not be valid after the action terminates.
setOption :: Socket a -> SocketOption -> IO ()Source
Set the given option on the socket. Please note that there are certain combatibility constraints w.r.t the socket type (cf. man zmq_setsockopt).
Please note that subscribe/unsubscribe is handled with separate functions.
getOption :: Socket a -> SocketOption -> IO SocketOptionSource
Get the given socket option by passing in some dummy value of that option. The actual value will be returned. Please note that there are certain combatibility constraints w.r.t the socket type (cf. man zmq_setsockopt).
unsubscribe :: SubsType a => Socket a -> String -> IO ()Source
Unsubscribe Socket from given subscription.
send :: Socket a -> ByteString -> [Flag] -> IO ()Source
Send the given ByteString
over the socket (zmq_send).
send' :: Socket a -> ByteString -> [Flag] -> IO ()Source
Send the given ByteString
over the socket (zmq_send).
This is operationally identical to send socket (Strict.concat
(Lazy.toChunks lbs)) flags
but may be more efficient.
moreToReceive :: Socket a -> IO BoolSource
Equivalent of ZMQ_RCVMORE, i.e. returns True if a multi-part message currently being read has more parts to follow, otherwise False.
Low-level functions
init :: Size -> IO ContextSource
Initialize a 0MQ context (cf. zmq_init for details). You should
normally prefer to use with
instead.
term :: Context -> IO ()Source
Terminate a 0MQ context (cf. zmq_term). You should normally
prefer to use with
instead.
socket :: SType a => Context -> a -> IO (Socket a)Source
Create a new 0MQ socket within the given context. withSocket
provides
automatic socket closing and may be safer to use.
close :: Socket a -> IO ()Source
Close a 0MQ socket. withSocket
provides automatic socket closing and may
be safer to use.
Type representing ZeroMQ devices, as used with zmq_device