zeromq4-haskell-0.6.7: Bindings to ZeroMQ 4.x

Copyright(c) 2013 Toralf Wittner
LicenseMIT
MaintainerToralf Wittner <tw@dtex.org>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell98

System.ZMQ4.Monadic

Contents

Description

This modules exposes a monadic interface of ZMQ4. 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 #

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

MonadBase IO (ZMQ z) # 

Methods

liftBase :: IO α -> ZMQ z α #

MonadBaseControl IO (ZMQ z) # 

Associated Types

type StM (ZMQ z :: * -> *) a :: * #

Methods

liftBaseWith :: (RunInBase (ZMQ z) IO -> IO a) -> ZMQ z a #

restoreM :: StM (ZMQ z) a -> ZMQ z a #

Monad (ZMQ z) # 

Methods

(>>=) :: ZMQ z a -> (a -> ZMQ z b) -> ZMQ z b #

(>>) :: ZMQ z a -> ZMQ z b -> ZMQ z b #

return :: a -> ZMQ z a #

fail :: String -> ZMQ z a #

Functor (ZMQ z) # 

Methods

fmap :: (a -> b) -> ZMQ z a -> ZMQ z b #

(<$) :: a -> ZMQ z b -> ZMQ z a #

Applicative (ZMQ z) # 

Methods

pure :: a -> ZMQ z a #

(<*>) :: ZMQ z (a -> b) -> ZMQ z a -> ZMQ z b #

(*>) :: ZMQ z a -> ZMQ z b -> ZMQ z b #

(<*) :: ZMQ z a -> ZMQ z b -> ZMQ z a #

MonadIO (ZMQ z) # 

Methods

liftIO :: IO a -> ZMQ z a #

MonadThrow (ZMQ z) # 

Methods

throwM :: Exception e => e -> ZMQ z a #

MonadCatch (ZMQ z) # 

Methods

catch :: Exception e => ZMQ z a -> (e -> ZMQ z a) -> ZMQ z a #

MonadMask (ZMQ z) # 

Methods

mask :: ((forall a. ZMQ z a -> ZMQ z a) -> ZMQ z b) -> ZMQ z b #

uninterruptibleMask :: ((forall a. ZMQ z a -> ZMQ z a) -> ZMQ z b) -> ZMQ z b #

type StM (ZMQ z) a # 
type StM (ZMQ z) a = a

data Socket z t #

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

Instances

SocketLike (Socket z) # 

Methods

toSocket :: Socket z t -> Socket t #

data Flag #

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

Constructors

DontWait

ZMQ_DONTWAIT (Only relevant on Windows.)

SendMore

ZMQ_SNDMORE

Instances

Eq Flag # 

Methods

(==) :: Flag -> Flag -> Bool #

(/=) :: Flag -> Flag -> Bool #

Ord Flag # 

Methods

compare :: Flag -> Flag -> Ordering #

(<) :: Flag -> Flag -> Bool #

(<=) :: Flag -> Flag -> Bool #

(>) :: Flag -> Flag -> Bool #

(>=) :: Flag -> Flag -> Bool #

max :: Flag -> Flag -> Flag #

min :: Flag -> Flag -> Flag #

Show Flag # 

Methods

showsPrec :: Int -> Flag -> ShowS #

show :: Flag -> String #

showList :: [Flag] -> ShowS #

data Switch #

Configuration switch

Constructors

Default

Use default setting

On

Activate setting

Off

De-activate setting

Instances

type Timeout = Int64 #

data Event #

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 s m where #

A Poll value contains the object to poll (a 0MQ socket or a file descriptor), the set of Events which are of interest and--optionally-- a callback-function which is invoked iff the set of interested events overlaps with the actual events.

Constructors

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

data KeyFormat a where #

Instances

Eq (KeyFormat a) # 

Methods

(==) :: KeyFormat a -> KeyFormat a -> Bool #

(/=) :: KeyFormat a -> KeyFormat a -> Bool #

Show (KeyFormat a) # 

Socket type-classes

class Sender a #

Sockets which can send.

class Subscriber a #

Sockets which can subscribe.

Instances

class SocketLike s #

Minimal complete definition

toSocket

Instances

SocketLike Socket # 

Methods

toSocket :: Socket t -> Socket t #

SocketLike (Socket z) # 

Methods

toSocket :: Socket z t -> Socket t #

class SendProbe a #

Sockets which can send probes (cf. setProbeRouter).

Socket Types

data Pair #

Constructors

Pair 

Instances

Eq Pair # 

Methods

(==) :: Pair -> Pair -> Bool #

(/=) :: Pair -> Pair -> Bool #

Generic Pair # 

Associated Types

type Rep Pair :: * -> * #

Methods

from :: Pair -> Rep Pair x #

to :: Rep Pair x -> Pair #

SocketType Pair # 
Receiver Pair # 
Sender Pair # 
type Rep Pair # 
type Rep Pair = D1 (MetaData "Pair" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Pair" PrefixI False) U1)

data Pub #

Constructors

Pub 

Instances

Eq Pub # 

Methods

(==) :: Pub -> Pub -> Bool #

(/=) :: Pub -> Pub -> Bool #

Generic Pub # 

Associated Types

type Rep Pub :: * -> * #

Methods

from :: Pub -> Rep Pub x #

to :: Rep Pub x -> Pub #

SocketType Pub # 
Conflatable Pub # 
Sender Pub # 
type Rep Pub # 
type Rep Pub = D1 (MetaData "Pub" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Pub" PrefixI False) U1)

data Sub #

Constructors

Sub 

Instances

Eq Sub # 

Methods

(==) :: Sub -> Sub -> Bool #

(/=) :: Sub -> Sub -> Bool #

Generic Sub # 

Associated Types

type Rep Sub :: * -> * #

Methods

from :: Sub -> Rep Sub x #

to :: Rep Sub x -> Sub #

SocketType Sub # 
Conflatable Sub # 
Receiver Sub # 
Subscriber Sub # 
type Rep Sub # 
type Rep Sub = D1 (MetaData "Sub" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Sub" PrefixI False) U1)

data XPub #

Constructors

XPub 

Instances

Eq XPub # 

Methods

(==) :: XPub -> XPub -> Bool #

(/=) :: XPub -> XPub -> Bool #

Generic XPub # 

Associated Types

type Rep XPub :: * -> * #

Methods

from :: XPub -> Rep XPub x #

to :: Rep XPub x -> XPub #

SocketType XPub # 
Receiver XPub # 
Sender XPub # 
type Rep XPub # 
type Rep XPub = D1 (MetaData "XPub" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "XPub" PrefixI False) U1)

data XSub #

Constructors

XSub 

Instances

Eq XSub # 

Methods

(==) :: XSub -> XSub -> Bool #

(/=) :: XSub -> XSub -> Bool #

Generic XSub # 

Associated Types

type Rep XSub :: * -> * #

Methods

from :: XSub -> Rep XSub x #

to :: Rep XSub x -> XSub #

SocketType XSub # 
Receiver XSub # 
Sender XSub # 
type Rep XSub # 
type Rep XSub = D1 (MetaData "XSub" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "XSub" PrefixI False) U1)

data Req #

Constructors

Req 

Instances

Eq Req # 

Methods

(==) :: Req -> Req -> Bool #

(/=) :: Req -> Req -> Bool #

Generic Req # 

Associated Types

type Rep Req :: * -> * #

Methods

from :: Req -> Rep Req x #

to :: Rep Req x -> Req #

SocketType Req # 
SendProbe Req # 
Receiver Req # 
Sender Req # 
type Rep Req # 
type Rep Req = D1 (MetaData "Req" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Req" PrefixI False) U1)

data Rep #

Constructors

Rep 

Instances

Eq Rep # 

Methods

(==) :: Rep -> Rep -> Bool #

(/=) :: Rep -> Rep -> Bool #

Generic Rep # 

Associated Types

type Rep Rep :: * -> * #

Methods

from :: Rep -> Rep Rep x #

to :: Rep Rep x -> Rep #

SocketType Rep # 
Receiver Rep # 
Sender Rep # 
type Rep Rep # 
type Rep Rep = D1 (MetaData "Rep" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Rep" PrefixI False) U1)

data Dealer #

Constructors

Dealer 

Instances

Eq Dealer # 

Methods

(==) :: Dealer -> Dealer -> Bool #

(/=) :: Dealer -> Dealer -> Bool #

Generic Dealer # 

Associated Types

type Rep Dealer :: * -> * #

Methods

from :: Dealer -> Rep Dealer x #

to :: Rep Dealer x -> Dealer #

SocketType Dealer # 
SendProbe Dealer # 
Conflatable Dealer # 
Receiver Dealer # 
Sender Dealer # 
type Rep Dealer # 
type Rep Dealer = D1 (MetaData "Dealer" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Dealer" PrefixI False) U1)

data Router #

Constructors

Router 

Instances

Eq Router # 

Methods

(==) :: Router -> Router -> Bool #

(/=) :: Router -> Router -> Bool #

Generic Router # 

Associated Types

type Rep Router :: * -> * #

Methods

from :: Router -> Rep Router x #

to :: Rep Router x -> Router #

SocketType Router # 
SendProbe Router # 
Receiver Router # 
Sender Router # 
type Rep Router # 
type Rep Router = D1 (MetaData "Router" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Router" PrefixI False) U1)

data Pull #

Constructors

Pull 

Instances

Eq Pull # 

Methods

(==) :: Pull -> Pull -> Bool #

(/=) :: Pull -> Pull -> Bool #

Generic Pull # 

Associated Types

type Rep Pull :: * -> * #

Methods

from :: Pull -> Rep Pull x #

to :: Rep Pull x -> Pull #

SocketType Pull # 
Conflatable Pull # 
Receiver Pull # 
type Rep Pull # 
type Rep Pull = D1 (MetaData "Pull" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Pull" PrefixI False) U1)

data Push #

Constructors

Push 

Instances

Eq Push # 

Methods

(==) :: Push -> Push -> Bool #

(/=) :: Push -> Push -> Bool #

Generic Push # 

Associated Types

type Rep Push :: * -> * #

Methods

from :: Push -> Rep Push x #

to :: Rep Push x -> Push #

SocketType Push # 
Conflatable Push # 
Sender Push # 
type Rep Push # 
type Rep Push = D1 (MetaData "Push" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Push" PrefixI False) U1)

data Stream #

Constructors

Stream 

Instances

Eq Stream # 

Methods

(==) :: Stream -> Stream -> Bool #

(/=) :: Stream -> Stream -> Bool #

Generic Stream # 

Associated Types

type Rep Stream :: * -> * #

Methods

from :: Stream -> Rep Stream x #

to :: Rep Stream x -> Stream #

SocketType Stream # 
Receiver Stream # 
Sender Stream # 
type Rep Stream # 
type Rep Stream = D1 (MetaData "Stream" "System.ZMQ4" "zeromq4-haskell-0.6.7-L3WUeGqXgmHq3WFLUvcLE" False) (C1 (MetaCons "Stream" PrefixI False) U1)

General Operations

version :: ZMQ z (Int, Int, Int) #

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

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

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

ZMQ Options (Read)

ZMQ Options (Write)

setIoThreads :: Word -> ZMQ z () #

setMaxSockets :: Word -> ZMQ z () #

Socket operations

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

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

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

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

disconnect :: Socket z t -> String -> ZMQ z () #

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

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

sendMulti :: Sender t => Socket z t -> NonEmpty ByteString -> ZMQ z () #

subscribe :: Subscriber t => Socket z t -> ByteString -> ZMQ z () #

unsubscribe :: Subscriber t => Socket z t -> ByteString -> ZMQ z () #

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

monitor :: [EventType] -> Socket z t -> ZMQ z (Bool -> IO (Maybe EventMsg)) #

socketMonitor :: [EventType] -> String -> Socket z t -> ZMQ z () #

poll :: (SocketLike s, MonadIO m) => Timeout -> [Poll s m] -> m [[Event]] #

Polls for events on the given Poll descriptors. Returns a list of events per descriptor which have occured. (cf. zmq_poll)

Socket Options (Read)

affinity :: Socket z t -> ZMQ z Word64 #

backlog :: Socket z t -> ZMQ z Int #

conflate :: Conflatable t => Socket z t -> ZMQ z Bool #

delayAttachOnConnect :: Socket z t -> ZMQ z Bool #

Deprecated: Use immediate

events :: Socket z t -> ZMQ z [Event] #

immediate :: Socket z t -> ZMQ z Bool #

ipv4Only :: Socket z t -> ZMQ z Bool #

Deprecated: Use ipv6

ipv6 :: Socket z t -> ZMQ z Bool #

linger :: Socket z t -> ZMQ z Int #

mcastHops :: Socket z t -> ZMQ z Int #

rate :: Socket z t -> ZMQ z Int #

sendBuffer :: Socket z t -> ZMQ z Int #

sendHighWM :: Socket z t -> ZMQ z Int #

sendTimeout :: Socket z t -> ZMQ z Int #

Socket Options (Write)

setAffinity :: Word64 -> Socket z t -> ZMQ z () #

setBacklog :: Integral i => Restricted (N0, Int32) i -> Socket z t -> ZMQ z () #

setConflate :: Conflatable t => Bool -> Socket z t -> ZMQ z () #

setCurveServer :: Bool -> Socket z t -> ZMQ z () #

setDelayAttachOnConnect :: Bool -> Socket z t -> ZMQ z () #

Deprecated: Use setImmediate

setImmediate :: Bool -> Socket z t -> ZMQ z () #

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

Deprecated: Use setIpv6

setIpv6 :: Bool -> Socket z t -> ZMQ z () #

setLinger :: Integral i => Restricted (Nneg1, Int32) i -> Socket z t -> ZMQ z () #

setMcastHops :: Integral i => Restricted (N1, Int32) i -> Socket z t -> ZMQ z () #

setPlainServer :: Bool -> Socket z t -> ZMQ z () #

setProbeRouter :: SendProbe t => Bool -> Socket z t -> ZMQ z () #

setRate :: Integral i => Restricted (N1, Int32) i -> Socket z t -> ZMQ z () #

setReceiveBuffer :: Integral i => Restricted (N0, Int32) i -> Socket z t -> ZMQ z () #

setReceiveHighWM :: Integral i => Restricted (N0, Int32) i -> Socket z t -> ZMQ z () #

setReqRelaxed :: Bool -> Socket z Req -> ZMQ z () #

setSendBuffer :: Integral i => Restricted (N0, Int32) i -> Socket z t -> ZMQ z () #

setSendHighWM :: Integral i => Restricted (N0, Int32) i -> Socket z t -> ZMQ z () #

setSendTimeout :: Integral i => Restricted (Nneg1, Int32) i -> Socket z t -> ZMQ z () #

setTcpKeepAlive :: Switch -> Socket z t -> ZMQ z () #

Error Handling

data ZMQError #

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

errno :: ZMQError -> Int #

Error number value.

source :: ZMQError -> String #

Source where this error originates from.

message :: ZMQError -> String #

Actual error message.

Re-exports

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

Lift a computation from the IO monad.

restrict :: Restriction r v => v -> Restricted r v #

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 r v => v -> Maybe (Restricted r v) #

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

Low-level Functions

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

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

curveKeyPair :: MonadIO m => m (Restricted Div5 ByteString, Restricted Div5 ByteString) #

Generate a new curve key pair. (cf. zmq_curve_keypair)