-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Bindings to ZeroMQ 3.x
--   
--   The 0MQ lightweight messaging kernel is a library which extends the
--   standard socket interfaces with features traditionally provided by
--   specialised messaging middleware products. 0MQ sockets provide an
--   abstraction of asynchronous message queues, multiple messaging
--   patterns, message filtering (subscriptions), seamless access to
--   multiple transport protocols and more. This library provides the
--   Haskell language binding to 0MQ &gt;= 3.2.2
@package zeromq3-haskell
@version 0.4


-- | Type-level restricted data. This module allows for type declarations
--   which embed certain restrictions, such as value bounds. E.g.
--   <tt>Restricted N0 N1 Int</tt> denotes an <a>Int</a> which can only
--   have values [0 .. 1]. When creating such a value, the constructor
--   functions <a>restrict</a> or <a>toRestricted</a> ensure that the
--   restrictions are obeyed. Code that consumes restricted types does not
--   need to check the constraints.
--   
--   <i>N.B.</i> This module is more or less tailored to be used within
--   <a>ZMQ3</a>. Therefore the provided type level restrictions are
--   limited.
module Data.Restricted

-- | Type level restriction.
data Restricted l u v

-- | A uniform way to restrict values.
class Restriction l u v
toRestricted :: Restriction l u v => v -> Maybe (Restricted l u v)
restrict :: Restriction l u v => v -> Restricted l u v

-- | Get the actual value.
rvalue :: Restricted l u v -> v

-- | type level -1
data Nneg1

-- | type-level 1
data N1

-- | type-level 0
data N0

-- | type-level 254
data N254

-- | type-level infinity
data Inf
instance Show v => Show (Restricted l u v)
instance Restriction N1 N254 ByteString
instance Restriction N1 N254 String
instance Integral a => Restriction Nneg1 Int64 a
instance Integral a => Restriction Nneg1 Int32 a
instance Integral a => Restriction Nneg1 Inf a
instance Integral a => Restriction N1 Int64 a
instance Integral a => Restriction N1 Int32 a
instance Integral a => Restriction N1 Inf a
instance Integral a => Restriction N0 Int64 a
instance Integral a => Restriction N0 Int32 a
instance Integral a => Restriction N0 Inf a
instance Show Inf
instance Show N254
instance Show N1
instance Show N0
instance Show Nneg1


-- | 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
--   <a>http://api.zeromq.org</a>
--   
--   Differences to zeromq-haskell 2.x
--   
--   <i>Socket Types</i>
--   
--   <ul>
--   <li><a>Up</a> and <a>Down</a> no longer exist.</li>
--   <li><a>XReq</a> is renamed to <a>Dealer</a> and <a>XRep</a> is renamed
--   to <a>Router</a> (in accordance with libzmq). <a>XReq</a> and
--   <a>XRep</a> are available as deprecated aliases.</li>
--   <li>Renamed type-classes: <tt><tt>SType</tt> -&gt;
--   <a>SocketType</a></tt>, <tt><tt>SubsType</tt> -&gt;
--   <a>Subscriber</a></tt>.</li>
--   <li>New type-classes: <a>Sender</a>, <a>Receiver</a></li>
--   </ul>
--   
--   <i>Socket Options</i>
--   
--   Instead of a single <tt>SocketOption</tt> data-type, getter and setter
--   functions are provided, e.g. one would write: <tt><a>affinity</a>
--   sock</tt> instead of <tt>getOption sock (Affinity 0)</tt>
--   
--   <i>Restrictions</i>
--   
--   Many option setters use a <a>Restriction</a> to further constrain the
--   range of possible values of their integral types. For example the
--   maximum message size can be given as -1, which means no limit or by
--   greater values, which denote the message size in bytes. The type of
--   <a>setMaxMessageSize</a> is therefore:
--   
--   <pre>
--   setMaxMessageSize :: <a>Integral</a> i =&gt; <a>Restricted</a> <a>Nneg1</a> <a>Int64</a> i -&gt; <a>Socket</a> a -&gt; <a>IO</a> ()
--   </pre>
--   
--   which means any integral value in the range of <tt>-1</tt> to
--   (<tt><a>maxBound</a> :: <a>Int64</a></tt>) can be given. To create a
--   restricted value from plain value, use <a>toRestricted</a> or
--   <a>restrict</a>.
--   
--   <i>Devices</i>
--   
--   Devices are no longer present in 0MQ 3.x and consequently have been
--   removed form this binding as well.
--   
--   <i>Error Handling</i>
--   
--   The type <a>ZMQError</a> is introduced, together with inspection
--   functions <a>errno</a>, <a>source</a> and <a>message</a>.
--   <tt>zmq_strerror</tt> is used underneath to retrieve the correct error
--   message. ZMQError will be thrown when native 0MQ procedures return an
--   error status and it can be <a>catch</a>ed as an <a>Exception</a>.
module System.ZMQ3
type Size = Word

-- | A 0MQ context representation.
data Context

-- | A 0MQ Socket.
data Socket a

-- | Flags to apply on send operations (cf. man zmq_send)
data Flag

-- | ZMQ_SNDMORE
SendMore :: Flag

-- | Configuration switch
data Switch

-- | Use default setting
Default :: Switch

-- | Activate setting
On :: Switch

-- | De-activate setting
Off :: Switch
type Timeout = Int64

-- | Socket events.
data Event

-- | ZMQ_POLLIN (incoming messages)
In :: Event

-- | ZMQ_POLLOUT (outgoing messages, i.e. at least 1 byte can be written)
Out :: Event

-- | ZMQ_POLLERR
Err :: Event

-- | Event types to monitor.
data EventType
ConnectedEvent :: EventType
ConnectDelayedEvent :: EventType
ConnectRetriedEvent :: EventType
ListeningEvent :: EventType
BindFailedEvent :: EventType
AcceptedEvent :: EventType
AcceptFailedEvent :: EventType
ClosedEvent :: EventType
CloseFailedEvent :: EventType
DisconnectedEvent :: EventType
AllEvents :: EventType

-- | Event Message to receive when monitoring socket events.
data EventMsg
Connected :: !ByteString -> !Fd -> EventMsg
ConnectDelayed :: !ByteString -> !Fd -> EventMsg
ConnectRetried :: !ByteString -> !Int -> EventMsg
Listening :: !ByteString -> !Fd -> EventMsg
BindFailed :: !ByteString -> !Fd -> EventMsg
Accepted :: !ByteString -> !Fd -> EventMsg
AcceptFailed :: !ByteString -> !Int -> EventMsg
Closed :: !ByteString -> !Fd -> EventMsg
CloseFailed :: !ByteString -> !Int -> EventMsg
Disconnected :: !ByteString -> !Int -> EventMsg

-- | Type representing a descriptor, poll is waiting for (either a 0MQ
--   socket or a file descriptor) plus the type of event to wait for.
data Poll m
Sock :: Socket s -> [Event] -> Maybe ([Event] -> m ()) -> Poll m
File :: Fd -> [Event] -> Maybe ([Event] -> m ()) -> Poll m

-- | Socket types.
class SocketType a

-- | Sockets which can <a>send</a>.
class Sender a

-- | Sockets which can <a>receive</a>.
class Receiver a

-- | Sockets which can <a>subscribe</a>.
class Subscriber a

-- | 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. <i>Compatible peer sockets</i>: <a>Pair</a>.
data Pair
Pair :: Pair

-- | Socket to distribute data. <a>receive</a> function is not implemented
--   for this socket type. Messages are distributed in fanout fashion to
--   all the peers. <i>Compatible peer sockets</i>: <a>Sub</a>.
data Pub
Pub :: Pub

-- | Socket to subscribe for data. <a>send</a> function is not implemented
--   for this socket type. Initially, socket is subscribed for no messages.
--   Use <a>subscribe</a> to specify which messages to subscribe for.
--   <i>Compatible peer sockets</i>: <a>Pub</a>.
data Sub
Sub :: Sub

-- | Same as <a>Pub</a> 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. <i>Compatible peer sockets</i>: <a>Sub</a>,
--   <a>XSub</a>.
data XPub
XPub :: XPub

-- | Same as <a>Sub</a> 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. <i>Compatible peer sockets</i>: <a>Pub</a>,
--   <a>XPub</a>.
data XSub
XSub :: XSub

-- | 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. <i>Compatible peer
--   sockets</i>: <a>Rep</a>, <a>Router</a>.
data Req
Req :: Req

-- | 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.
--   <i>Compatible peer sockets</i>: <a>Req</a>, <a>Dealer</a>.
data Rep
Rep :: Rep

-- | Each message sent is round-robined among all connected peers, and each
--   message received is fair-queued from all connected peers.
--   <i>Compatible peer sockets</i>: <a>Router</a>, <a>Req</a>, <a>Rep</a>.
data Dealer
Dealer :: Dealer

-- | 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.
--   <i>Compatible peer sockets</i>: <a>Dealer</a>, <a>Req</a>, <a>Rep</a>.
data Router
Router :: Router

-- | <i>Deprecated Alias</i>

-- | <i>Deprecated: Use Dealer </i>
type XReq = Dealer

-- | <i>Deprecated Alias</i>

-- | <i>Deprecated: Use Router </i>
type XRep = Router

-- | 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.
data Pull
Pull :: Pull

-- | 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.
data Push
Push :: Push

-- | Run an action with a 0MQ context. The <a>Context</a> supplied to your
--   action will <i>not</i> be valid after the action either returns or
--   throws an exception.
withContext :: (Context -> IO a) -> IO a

-- | 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 <i>not</i> be valid after the action
--   terminates.
withSocket :: SocketType a => Context -> a -> (Socket a -> IO b) -> IO b

-- | Bind the socket to the given address (cf. zmq_bind)
bind :: Socket a -> String -> IO ()

-- | Unbind the socket from the given address (cf. zmq_unbind)
unbind :: Socket a -> String -> IO ()

-- | Connect the socket to the given address (cf. zmq_connect).
connect :: Socket a -> String -> IO ()

-- | Send the given <a>ByteString</a> over the socket (cf. zmq_sendmsg).
--   
--   <i>Note</i>: This function always calls <tt>zmq_sendmsg</tt> in a
--   non-blocking way, i.e. there is no need to provide the
--   <tt>ZMQ_DONTWAIT</tt> flag as this is used by default. Still
--   <a>send</a> is blocking the thread as long as the message can not be
--   queued on the socket using GHC's <a>threadWaitWrite</a>.
send :: Sender a => Socket a -> [Flag] -> ByteString -> IO ()

-- | Send the given <a>ByteString</a> over the socket (cf. zmq_sendmsg).
--   This is operationally identical to <tt>send socket (Strict.concat
--   (Lazy.toChunks lbs)) flags</tt> but may be more efficient.
--   
--   <i>Note</i>: This function always calls <tt>zmq_sendmsg</tt> in a
--   non-blocking way, i.e. there is no need to provide the
--   <tt>ZMQ_DONTWAIT</tt> flag as this is used by default. Still
--   <a>send'</a> is blocking the thread as long as the message can not be
--   queued on the socket using GHC's <a>threadWaitWrite</a>.
send' :: Sender a => Socket a -> [Flag] -> ByteString -> IO ()

-- | Send a multi-part message. This function applies the <a>SendMore</a>
--   <a>Flag</a> between all message parts. 0MQ guarantees atomic delivery
--   of a multi-part message (cf. zmq_sendmsg for details).
sendMulti :: Sender a => Socket a -> NonEmpty ByteString -> IO ()

-- | Receive a <tt>ByteString</tt> from socket (cf. zmq_recvmsg).
--   
--   <i>Note</i>: This function always calls <tt>zmq_recvmsg</tt> in a
--   non-blocking way, i.e. there is no need to provide the
--   <tt>ZMQ_DONTWAIT</tt> flag as this is used by default. Still
--   <a>receive</a> is blocking the thread as long as no data is available
--   using GHC's <a>threadWaitRead</a>.
receive :: Receiver a => Socket a -> IO (ByteString)

-- | Receive a multi-part message. This function collects all message parts
--   send via <a>sendMulti</a>.
receiveMulti :: Receiver a => Socket a -> IO [ByteString]

-- | Return the runtime version of the underlying 0MQ library as a (major,
--   minor, patch) triple.
version :: IO (Int, Int, Int)

-- | Monitor socket events. This function returns a function which can be
--   invoked to retrieve the next socket event, potentially blocking until
--   the next one becomes available. When applied to <a>False</a>,
--   monitoring will terminate, i.e. internal monitoring resources will be
--   disposed. Consequently after <a>monitor</a> has been invoked, the
--   returned function must be applied <i>once</i> to <a>False</a>.
monitor :: [EventType] -> Context -> Socket a -> IO (Bool -> IO (Maybe EventMsg))

-- | Polls for events on the given <a>Poll</a> descriptors. Returns the
--   same list of <a>Poll</a> descriptors with an <a>updated</a>
--   <tt>PollEvent</tt> field (cf. zmq_poll). Sockets which have seen no
--   activity have <tt>None</tt> in their <tt>PollEvent</tt> field.
poll :: MonadIO m => Timeout -> [Poll m] -> m [[Event]]

-- | Subscribe Socket to given subscription.
subscribe :: Subscriber a => Socket a -> ByteString -> IO ()

-- | Unsubscribe Socket from given subscription.
unsubscribe :: Subscriber a => Socket a -> ByteString -> IO ()

-- | Cf. <tt>zmq_ctx_get ZMQ_IO_THREADS</tt>
ioThreads :: Context -> IO Word

-- | Cf. <tt>zmq_ctx_get ZMQ_MAX_SOCKETS</tt>
maxSockets :: Context -> IO Word

-- | Cf. <tt>zmq_ctx_set ZMQ_IO_THREADS</tt>
setIoThreads :: Word -> Context -> IO ()

-- | Cf. <tt>zmq_ctx_set ZMQ_MAX_SOCKETS</tt>
setMaxSockets :: Word -> Context -> IO ()

-- | Cf. <tt>zmq_getsockopt ZMQ_AFFINITY</tt>
affinity :: Socket a -> IO Word64

-- | Cf. <tt>zmq_getsockopt ZMQ_BACKLOG</tt>
backlog :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_DELAY_ATTACH_ON_CONNECT</tt>
delayAttachOnConnect :: Socket a -> IO Bool

-- | Cf. <tt>zmq_getsockopt ZMQ_EVENTS</tt>
events :: Socket a -> IO [Event]

-- | Cf. <tt>zmq_getsockopt ZMQ_FD</tt>
fileDescriptor :: Socket a -> IO Fd

-- | Cf. <tt>zmq_getsockopt ZMQ_IDENTITY</tt>
identity :: Socket a -> IO ByteString

-- | Cf. <tt>zmq_getsockopt ZMQ_IPV4ONLY</tt>
ipv4Only :: Socket a -> IO Bool

-- | Cf. <tt>zmq_getsockopt ZMQ_LAST_ENDPOINT</tt>
lastEndpoint :: Socket a -> IO String

-- | Cf. <tt>zmq_getsockopt ZMQ_LINGER</tt>
linger :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_MAXMSGSIZE</tt>
maxMessageSize :: Socket a -> IO Int64

-- | Cf. <tt>zmq_getsockopt ZMQ_MULTICAST_HOPS</tt>
mcastHops :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_RCVMORE</tt>
moreToReceive :: Socket a -> IO Bool

-- | Cf. <tt>zmq_getsockopt ZMQ_RATE</tt>
rate :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_RCVBUF</tt>
receiveBuffer :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_RCVHWM</tt>
receiveHighWM :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_RCVTIMEO</tt>
receiveTimeout :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_RECONNECT_IVL</tt>
reconnectInterval :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_RECONNECT_IVL_MAX</tt>
reconnectIntervalMax :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_RECOVERY_IVL</tt>
recoveryInterval :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_SNDBUF</tt>
sendBuffer :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_SNDHWM</tt>
sendHighWM :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_SNDTIMEO</tt>
sendTimeout :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_TCP_KEEPALIVE</tt>
tcpKeepAlive :: Socket a -> IO Switch

-- | Cf. <tt>zmq_getsockopt ZMQ_TCP_KEEPALIVE_CNT</tt>
tcpKeepAliveCount :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_TCP_KEEPALIVE_IDLE</tt>
tcpKeepAliveIdle :: Socket a -> IO Int

-- | Cf. <tt>zmq_getsockopt ZMQ_TCP_KEEPALIVE_INTVL</tt>
tcpKeepAliveInterval :: Socket a -> IO Int

-- | Cf. <tt>zmq_setsockopt ZMQ_AFFINITY</tt>
setAffinity :: Word64 -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_BACKLOG</tt>
setBacklog :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_DELAY_ATTACH_ON_CONNECT</tt>
setDelayAttachOnConnect :: Bool -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_IDENTITY</tt>
setIdentity :: Restricted N1 N254 ByteString -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_IPV4ONLY</tt>
setIpv4Only :: Bool -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_LINGER</tt>
setLinger :: Integral i => Restricted Nneg1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_MAXMSGSIZE</tt>
setMaxMessageSize :: Integral i => Restricted Nneg1 Int64 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_MULTICAST_HOPS</tt>
setMcastHops :: Integral i => Restricted N1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_RATE</tt>
setRate :: Integral i => Restricted N1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_RCVBUF</tt>
setReceiveBuffer :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_RCVHWM</tt>
setReceiveHighWM :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_RCVTIMEO</tt>
setReceiveTimeout :: Integral i => Restricted Nneg1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_RECONNECT_IVL</tt>
setReconnectInterval :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_RECONNECT_IVL_MAX</tt>
setReconnectIntervalMax :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_RECOVERY_IVL</tt>
setRecoveryInterval :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_ROUTER_MANDATORY</tt>
setRouterMandatory :: Bool -> Socket Router -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_SNDBUF</tt>
setSendBuffer :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_SNDHWM</tt>
setSendHighWM :: Integral i => Restricted N0 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_SNDTIMEO</tt>
setSendTimeout :: Integral i => Restricted Nneg1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_TCP_ACCEPT_FILTER</tt>
setTcpAcceptFilter :: Maybe ByteString -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_TCP_KEEPALIVE</tt>
setTcpKeepAlive :: Switch -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_TCP_KEEPALIVE_CNT</tt>
setTcpKeepAliveCount :: Integral i => Restricted Nneg1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_TCP_KEEPALIVE_IDLE</tt>
setTcpKeepAliveIdle :: Integral i => Restricted Nneg1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_TCP_KEEPALIVE_INTVL</tt>
setTcpKeepAliveInterval :: Integral i => Restricted Nneg1 Int32 i -> Socket a -> IO ()

-- | Cf. <tt>zmq_setsockopt ZMQ_XPUB_VERBOSE</tt>
setXPubVerbose :: Bool -> Socket XPub -> IO ()

-- | 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.
restrict :: Restriction l u v => v -> Restricted l u v

-- | Create a restricted value. Returns <a>Nothing</a> if the given value
--   does not satisfy all restrictions.
toRestricted :: Restriction l u v => v -> Maybe (Restricted l u v)

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

-- | Error number value.
errno :: ZMQError -> Int

-- | Source where this error originates from.
source :: ZMQError -> String

-- | Actual error message.
message :: ZMQError -> String

-- | <i>Deprecated: Use context </i>
init :: Size -> IO Context

-- | <i>Deprecated: Use destroy </i>
term :: Context -> IO ()

-- | Initialize a 0MQ context (cf. zmq_ctx_new for details). You should
--   normally prefer to use <a>withContext</a> instead.
context :: IO Context

-- | Terminate a 0MQ context (cf. zmq_ctx_destroy). You should normally
--   prefer to use <a>withContext</a> instead.
destroy :: Context -> IO ()

-- | Create a new 0MQ socket within the given context. <a>withSocket</a>
--   provides automatic socket closing and may be safer to use.
socket :: SocketType a => Context -> a -> IO (Socket a)

-- | Close a 0MQ socket. <a>withSocket</a> provides automatic socket
--   closing and may be safer to use.
close :: Socket a -> IO ()

-- | Wait until data is available for reading from the given Socket. After
--   this function returns, a call to <a>receive</a> will essentially be
--   non-blocking.
waitRead :: Socket a -> IO ()

-- | Wait until data can be written to the given Socket. After this
--   function returns, a call to <a>send</a> will essentially be
--   non-blocking.
waitWrite :: Socket a -> IO ()

-- | Starts built-in 0MQ proxy.
--   
--   Proxy connects front to back socket
--   
--   Before calling proxy all sockets should be binded
--   
--   If the capture socket is not Nothing, the proxy shall send all
--   messages, received on both frontend and backend, to the capture
--   socket.
proxy :: Socket a -> Socket b -> Maybe (Socket c) -> IO ()
instance Eq Event
instance Ord Event
instance Read Event
instance Show Event
instance Sender Push
instance SocketType Push
instance Receiver Pull
instance SocketType Pull
instance Receiver Router
instance Sender Router
instance SocketType Router
instance Receiver Dealer
instance Sender Dealer
instance SocketType Dealer
instance Receiver Rep
instance Sender Rep
instance SocketType Rep
instance Receiver Req
instance Sender Req
instance SocketType Req
instance Receiver XSub
instance Sender XSub
instance SocketType XSub
instance Receiver XPub
instance Sender XPub
instance SocketType XPub
instance Receiver Sub
instance Subscriber Sub
instance SocketType Sub
instance Sender Pub
instance SocketType Pub
instance Receiver Pair
instance Sender Pair
instance SocketType Pair


-- | This modules exposes a monadic interface of <a>ZMQ3</a>. Actions run
--   inside a <a>ZMQ</a> monad and <a>Socket</a>s are guaranteed not to
--   leak outside their corresponding <a>runZMQ</a> scope. Running
--   <a>ZMQ</a> computations asynchronously is directly supported through
--   <a>async</a>.
module System.ZMQ3.Monadic

-- | The ZMQ monad is modeled after <a>ST</a> and encapsulates a
--   <a>Context</a>. It uses the uninstantiated type variable <tt>z</tt> to
--   distinguish different invoctions of <a>runZMQ</a> and to prevent
--   unintented use of <a>Socket</a>s outside their scope. Cf. the paper of
--   John Launchbury and Simon Peyton Jones <i>Lazy Functional State
--   Threads</i>.
data ZMQ z a

-- | The ZMQ socket, parameterised by <tt>SocketType</tt> and belonging to
--   a particular <a>ZMQ</a> thread.
data Socket z t

-- | Flags to apply on send operations (cf. man zmq_send)
data Flag

-- | ZMQ_SNDMORE
SendMore :: Flag

-- | Configuration switch
data Switch

-- | Use default setting
Default :: Switch

-- | Activate setting
On :: Switch

-- | De-activate setting
Off :: Switch
type Timeout = Int64

-- | Socket events.
data Event

-- | ZMQ_POLLIN (incoming messages)
In :: Event

-- | ZMQ_POLLOUT (outgoing messages, i.e. at least 1 byte can be written)
Out :: Event

-- | ZMQ_POLLERR
Err :: Event

-- | Event types to monitor.
data EventType
ConnectedEvent :: EventType
ConnectDelayedEvent :: EventType
ConnectRetriedEvent :: EventType
ListeningEvent :: EventType
BindFailedEvent :: EventType
AcceptedEvent :: EventType
AcceptFailedEvent :: EventType
ClosedEvent :: EventType
CloseFailedEvent :: EventType
DisconnectedEvent :: EventType
AllEvents :: EventType

-- | Event Message to receive when monitoring socket events.
data EventMsg
Connected :: !ByteString -> !Fd -> EventMsg
ConnectDelayed :: !ByteString -> !Fd -> EventMsg
ConnectRetried :: !ByteString -> !Int -> EventMsg
Listening :: !ByteString -> !Fd -> EventMsg
BindFailed :: !ByteString -> !Fd -> EventMsg
Accepted :: !ByteString -> !Fd -> EventMsg
AcceptFailed :: !ByteString -> !Int -> EventMsg
Closed :: !ByteString -> !Fd -> EventMsg
CloseFailed :: !ByteString -> !Int -> EventMsg
Disconnected :: !ByteString -> !Int -> EventMsg

-- | Type representing a descriptor, poll is waiting for (either a 0MQ
--   socket or a file descriptor) plus the type of event to wait for.
data Poll m
Sock :: Socket s -> [Event] -> Maybe ([Event] -> m ()) -> Poll m
File :: Fd -> [Event] -> Maybe ([Event] -> m ()) -> Poll m

-- | Socket types.
class SocketType a

-- | Sockets which can <a>send</a>.
class Sender a

-- | Sockets which can <a>receive</a>.
class Receiver a

-- | Sockets which can <a>subscribe</a>.
class Subscriber a

-- | 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. <i>Compatible peer sockets</i>: <a>Pair</a>.
data Pair
Pair :: Pair

-- | Socket to distribute data. <a>receive</a> function is not implemented
--   for this socket type. Messages are distributed in fanout fashion to
--   all the peers. <i>Compatible peer sockets</i>: <a>Sub</a>.
data Pub
Pub :: Pub

-- | Socket to subscribe for data. <a>send</a> function is not implemented
--   for this socket type. Initially, socket is subscribed for no messages.
--   Use <a>subscribe</a> to specify which messages to subscribe for.
--   <i>Compatible peer sockets</i>: <a>Pub</a>.
data Sub
Sub :: Sub

-- | Same as <a>Pub</a> 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. <i>Compatible peer sockets</i>: <a>Sub</a>,
--   <a>XSub</a>.
data XPub
XPub :: XPub

-- | Same as <a>Sub</a> 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. <i>Compatible peer sockets</i>: <a>Pub</a>,
--   <a>XPub</a>.
data XSub
XSub :: XSub

-- | 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. <i>Compatible peer
--   sockets</i>: <a>Rep</a>, <a>Router</a>.
data Req
Req :: Req

-- | 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.
--   <i>Compatible peer sockets</i>: <a>Req</a>, <a>Dealer</a>.
data Rep
Rep :: Rep

-- | Each message sent is round-robined among all connected peers, and each
--   message received is fair-queued from all connected peers.
--   <i>Compatible peer sockets</i>: <a>Router</a>, <a>Req</a>, <a>Rep</a>.
data Dealer
Dealer :: Dealer

-- | 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.
--   <i>Compatible peer sockets</i>: <a>Dealer</a>, <a>Req</a>, <a>Rep</a>.
data Router
Router :: Router

-- | 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.
data Pull
Pull :: Pull

-- | 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.
data Push
Push :: Push
version :: ZMQ z (Int, Int, Int)

-- | Return the value computed by the given <a>ZMQ</a> monad. Rank-2
--   polymorphism is used to prevent leaking of <tt>z</tt>. An invocation
--   of <a>runZMQ</a> will internally create a <a>Context</a> and all
--   actions are executed relative to this context. On finish the context
--   will be disposed, but see <a>async</a>.
runZMQ :: MonadIO m => (forall z. ZMQ z a) -> m a

-- | Run the given <a>ZMQ</a> computation asynchronously, i.e. this
--   function runs the computation in a new thread using <a>async</a>.
--   <i>N.B.</i> reference counting is used to prolong the lifetime of the
--   <a>Context</a> encapsulated in <a>ZMQ</a> as necessary, e.g.:
--   
--   <pre>
--   runZMQ $ do
--       s &lt;- socket Pair
--       async $ do
--           liftIO (threadDelay 10000000)
--           identity s &gt;&gt;= liftIO . print
--   </pre>
--   
--   Here, <a>runZMQ</a> will finish before the code section in
--   <a>async</a>, but due to reference counting, the <a>Context</a> will
--   only be disposed after <a>async</a> finishes as well.
async :: ZMQ z a -> ZMQ z (Async a)
socket :: SocketType t => t -> ZMQ z (Socket z t)
ioThreads :: ZMQ z Word
maxSockets :: ZMQ z Word
setIoThreads :: Word -> ZMQ z ()
setMaxSockets :: Word -> ZMQ z ()
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 ()
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 ()
receive :: Receiver t => Socket z t -> ZMQ z ByteString
receiveMulti :: Receiver t => Socket z t -> ZMQ z [ByteString]
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))

-- | Polls for events on the given <a>Poll</a> descriptors. Returns the
--   same list of <a>Poll</a> descriptors with an <a>updated</a>
--   <tt>PollEvent</tt> field (cf. zmq_poll). Sockets which have seen no
--   activity have <tt>None</tt> in their <tt>PollEvent</tt> field.
poll :: MonadIO m => Timeout -> [Poll m] -> m [[Event]]
affinity :: Socket z t -> ZMQ z Word64
backlog :: Socket z t -> ZMQ z Int
delayAttachOnConnect :: Socket z t -> ZMQ z Bool
events :: Socket z t -> ZMQ z [Event]
fileDescriptor :: Socket z t -> ZMQ z Fd
identity :: Socket z t -> ZMQ z ByteString
ipv4Only :: Socket z t -> ZMQ z Bool
lastEndpoint :: Socket z t -> ZMQ z String
linger :: Socket z t -> ZMQ z Int
maxMessageSize :: Socket z t -> ZMQ z Int64
mcastHops :: Socket z t -> ZMQ z Int
moreToReceive :: Socket z t -> ZMQ z Bool
rate :: Socket z t -> ZMQ z Int
receiveBuffer :: Socket z t -> ZMQ z Int
receiveHighWM :: Socket z t -> ZMQ z Int
receiveTimeout :: Socket z t -> ZMQ z Int
reconnectInterval :: Socket z t -> ZMQ z Int
reconnectIntervalMax :: Socket z t -> ZMQ z Int
recoveryInterval :: 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
tcpKeepAlive :: Socket z t -> ZMQ z Switch
tcpKeepAliveCount :: Socket z t -> ZMQ z Int
tcpKeepAliveIdle :: Socket z t -> ZMQ z Int
tcpKeepAliveInterval :: Socket z t -> ZMQ z Int
setAffinity :: Word64 -> Socket z t -> ZMQ z ()
setBacklog :: Integral i => Restricted N0 Int32 i -> Socket z t -> ZMQ z ()
setDelayAttachOnConnect :: Bool -> Socket z t -> ZMQ z ()
setIdentity :: Restricted N1 N254 ByteString -> Socket z t -> ZMQ z ()
setIpv4Only :: Bool -> Socket z t -> ZMQ z ()
setLinger :: Integral i => Restricted Nneg1 Int32 i -> Socket z t -> ZMQ z ()
setMaxMessageSize :: Integral i => Restricted Nneg1 Int64 i -> Socket z t -> ZMQ z ()
setMcastHops :: Integral i => Restricted N1 Int32 i -> 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 ()
setReceiveTimeout :: Integral i => Restricted Nneg1 Int32 i -> Socket z t -> ZMQ z ()
setReconnectInterval :: Integral i => Restricted N0 Int32 i -> Socket z t -> ZMQ z ()
setReconnectIntervalMax :: Integral i => Restricted N0 Int32 i -> Socket z t -> ZMQ z ()
setRecoveryInterval :: Integral i => Restricted N0 Int32 i -> Socket z t -> ZMQ z ()
setRouterMandatory :: Bool -> Socket z Router -> 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 ()
setTcpAcceptFilter :: Maybe ByteString -> Socket z t -> ZMQ z ()
setTcpKeepAlive :: Switch -> Socket z t -> ZMQ z ()
setTcpKeepAliveCount :: Integral i => Restricted Nneg1 Int32 i -> Socket z t -> ZMQ z ()
setTcpKeepAliveIdle :: Integral i => Restricted Nneg1 Int32 i -> Socket z t -> ZMQ z ()
setTcpKeepAliveInterval :: Integral i => Restricted Nneg1 Int32 i -> Socket z t -> ZMQ z ()
setXPubVerbose :: Bool -> Socket z XPub -> ZMQ z ()

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

-- | Error number value.
errno :: ZMQError -> Int

-- | Source where this error originates from.
source :: ZMQError -> String

-- | Actual error message.
message :: ZMQError -> String

-- | Lift a computation from the <a>IO</a> monad.
liftIO :: MonadIO m => forall a. IO a -> m a

-- | 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.
restrict :: Restriction l u v => v -> Restricted l u v

-- | Create a restricted value. Returns <a>Nothing</a> if the given value
--   does not satisfy all restrictions.
toRestricted :: Restriction l u v => v -> Maybe (Restricted l u v)
waitRead :: Socket z t -> ZMQ z ()
waitWrite :: Socket z t -> ZMQ z ()
instance Applicative (ZMQ z)
instance Functor (ZMQ z)
instance MonadCatchIO (ZMQ z)
instance MonadIO (ZMQ z)
instance Monad (ZMQ z)
