zeromq3-haskell-0.4: Bindings to ZeroMQ 3.x

Portabilitynon-portable
Stabilityexperimental
MaintainerToralf Wittner <tw@dtex.org>
Safe HaskellNone

System.ZMQ3.Monadic

Contents

Description

This modules exposes a monadic interface of ZMQ3. Actions run inside a ZMQ monad and Sockets are guaranteed not to leak outside their corresponding runZMQ scope. Running ZMQ computations asynchronously is directly supported through async.

Synopsis

Type Definitions

data ZMQ z a Source

The ZMQ monad is modeled after ST and encapsulates a Context. It uses the uninstantiated type variable z to distinguish different invoctions of runZMQ and to prevent unintented use of Sockets outside their scope. Cf. the paper of John Launchbury and Simon Peyton Jones Lazy Functional State Threads.

Instances

data Socket z t Source

The ZMQ socket, parameterised by SocketType and belonging to a particular ZMQ thread.

data Flag Source

Flags to apply on send operations (cf. man zmq_send)

Constructors

SendMore

ZMQ_SNDMORE

Instances

data Switch Source

Configuration switch

Constructors

Default

Use default setting

On

Activate setting

Off

De-activate setting

Instances

data Event Source

Socket events.

Constructors

In

ZMQ_POLLIN (incoming messages)

Out

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

Err

ZMQ_POLLERR

data Poll m whereSource

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

Sock :: Socket s -> [Event] -> Maybe ([Event] -> m ()) -> Poll m 
File :: Fd -> [Event] -> Maybe ([Event] -> m ()) -> Poll m 

Type Classes

class Subscriber a Source

Sockets which can subscribe.

Instances

Socket Types

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 

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 

data XPub Source

Same as Pub except that you can receive subscriptions from the peers in form of incoming messages. Subscription message is a byte 1 (for subscriptions) or byte 0 (for unsubscriptions) followed by the subscription body. Compatible peer sockets: Sub, XSub.

Constructors

XPub 

data XSub Source

Same as Sub except that you subscribe by sending subscription messages to the socket. Subscription message is a byte 1 (for subscriptions) or byte 0 (for unsubscriptions) followed by the subscription body. Compatible peer sockets: Pub, XPub.

Constructors

XSub 

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, Router.

Constructors

Req 

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, Dealer.

Constructors

Rep 

data Dealer Source

Each message sent is round-robined among all connected peers, and each message received is fair-queued from all connected peers. Compatible peer sockets: Router, Req, Rep.

Constructors

Dealer 

data Router Source

When receiving messages a Router socket shall prepend a message part containing the identity of the originating peer to the message before passing it to the application. Messages received are fair-queued from among all connected peers. When sending messages a Router socket shall remove the first part of the message and use it to determine the identity of the peer the message shall be routed to. If the peer does not exist anymore the message shall be silently discarded. Compatible peer sockets: Dealer, Req, Rep.

Constructors

Router 

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 

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 

General Operations

runZMQ :: MonadIO m => (forall z. ZMQ z a) -> m aSource

Return the value computed by the given ZMQ monad. Rank-2 polymorphism is used to prevent leaking of z. An invocation of runZMQ will internally create a Context and all actions are executed relative to this context. On finish the context will be disposed, but see async.

async :: ZMQ z a -> ZMQ z (Async a)Source

Run the given ZMQ computation asynchronously, i.e. this function runs the computation in a new thread using async. N.B. reference counting is used to prolong the lifetime of the Context encapsulated in ZMQ as necessary, e.g.:

 runZMQ $ do
     s <- socket Pair
     async $ do
         liftIO (threadDelay 10000000)
         identity s >>= liftIO . print

Here, runZMQ will finish before the code section in async, but due to reference counting, the Context will only be disposed after async finishes as well.

socket :: SocketType t => t -> ZMQ z (Socket z t)Source

ZMQ Options (Read)

ZMQ Options (Write)

Socket operations

close :: Socket z t -> ZMQ z ()Source

bind :: Socket z t -> String -> ZMQ z ()Source

unbind :: Socket z t -> String -> ZMQ z ()Source

connect :: Socket z t -> String -> ZMQ z ()Source

send :: Sender t => Socket z t -> [Flag] -> ByteString -> ZMQ z ()Source

send' :: Sender t => Socket z t -> [Flag] -> ByteString -> ZMQ z ()Source

proxy :: Socket z a -> Socket z b -> Maybe (Socket z c) -> ZMQ z ()Source

poll :: MonadIO m => Timeout -> [Poll m] -> m [[Event]]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.

Socket Options (Read)

rate :: Socket z t -> ZMQ z IntSource

Socket Options (Write)

setIpv4Only :: Bool -> Socket z t -> ZMQ z ()Source

Error Handling

data ZMQError Source

ZMQError encapsulates information about errors, which occur when using the native 0MQ API, such as error number and message.

errno :: ZMQError -> IntSource

Error number value.

source :: ZMQError -> StringSource

Source where this error originates from.

message :: ZMQError -> StringSource

Actual error message.

Re-exports

liftIO :: MonadIO m => forall a. IO a -> m a

Lift a computation from the IO monad.

restrict :: Restriction l u v => v -> Restricted l u vSource

Create a restricted value. If the given value does not satisfy the restrictions, a modified variant is used instead, e.g. if an integer is larger than the upper bound, the upper bound value is used.

toRestricted :: Restriction l u v => v -> Maybe (Restricted l u v)Source

Create a restricted value. Returns Nothing if the given value does not satisfy all restrictions.

Low-level Functions

waitRead :: Socket z t -> ZMQ z ()Source

waitWrite :: Socket z t -> ZMQ z ()Source