zeromq-haskell-0.8.4: Bindings to ZeroMQ 2.1.x

Portabilitynon-portable
Stabilityexperimental
Maintainertoralf.wittner@gmail.com
Safe HaskellSafe-Infered

System.ZMQ

Contents

Description

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

Synopsis

Documentation

data Context Source

A 0MQ context representation.

data Socket a Source

A 0MQ Socket.

data Flag Source

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

Constructors

NoBlock

ZMQ_NOBLOCK (0MQ-2.x), ZMQ_DONTWAIT (0MQ-3.x)

SndMore

ZMQ_SNDMORE

Instances

data SocketOption Source

The option to set on 0MQ sockets (cf. zmq_setsockopt and zmq_getsockopt manpages for details).

Constructors

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

data Poll Source

Type representing a descriptor, poll is waiting for (either a 0MQ socket or a file descriptor) plus the type of event to wait for.

Constructors

forall a . S (Socket a) PollEvent 
F Fd PollEvent 

data PollEvent Source

The events to wait for in poll (cf. man zmq_poll)

Constructors

In

ZMQ_POLLIN (incoming messages)

Out

ZMQ_POLLOUT (outgoing messages, i.e. at least 1 byte can be written)

InOut

ZMQ_POLLIN | ZMQ_POLLOUT

Native

ZMQ_POLLERR

None 

class SubsType a Source

Subscribable.

Instances

data Pair Source

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.

Constructors

Pair 

Instances

data Pub Source

Socket to distribute data. receive function is not implemented for this socket type. Messages are distributed in fanout fashion to all the peers. Compatible peer sockets: Sub.

Constructors

Pub 

Instances

data Sub Source

Socket to subscribe for data. Send function is not implemented for this socket type. Initially, socket is subscribed for no messages. Use subscribe to specify which messages to subscribe for. Compatible peer sockets: Pub.

Constructors

Sub 

Instances

data Req Source

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.

Constructors

Req 

Instances

data Rep Source

Socket to receive requests and send replies. This socket type allows only an alternated sequence of receive's and send's. Each send is routed to the peer that issued the last received request. Compatible peer sockets: Req, XReq.

Constructors

Rep 

Instances

data XReq Source

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.

Constructors

XReq 

Instances

data XRep Source

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.

Constructors

XRep 

Instances

data Dealer Source

Constructors

Dealer 

Instances

data Router Source

Constructors

Router 

Instances

data Pull Source

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.

Constructors

Pull 

Instances

data Push Source

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.

Constructors

Push 

Instances

data Up Source

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.

Constructors

Up 

Instances

data Down Source

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.

Constructors

Down 

Instances

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

subscribe :: SubsType a => Socket a -> String -> IO ()Source

Subscribe Socket to given subscription.

unsubscribe :: SubsType a => Socket a -> String -> IO ()Source

Unsubscribe Socket from given subscription.

bind :: Socket a -> String -> IO ()Source

Bind the socket to the given address (zmq_bind)

connect :: Socket a -> String -> IO ()Source

Connect the socket to the given address (zmq_connect).

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.

receive :: Socket a -> [Flag] -> IO ByteStringSource

Receive a ByteString from socket (zmq_recv).

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.

poll :: [Poll] -> Timeout -> IO [Poll]Source

Polls for events on the given Poll descriptors. Returns the same list of Poll descriptors with an updated PollEvent field (cf. zmq_poll). Sockets which have seen no activity have None in their PollEvent field.

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.

data Device Source

Type representing ZeroMQ devices, as used with zmq_device

Constructors

Streamer

ZMQ_STREAMER

Forwarder

ZMQ_FORWARDER

Queue

ZMQ_QUEUE

Instances

device :: Device -> Socket a -> Socket b -> IO ()Source

Launch a ZeroMQ device (zmq_device).

Please note that this call never returns.