Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Pair = Pair
- data Req = Req
- data Rep = Rep
- data Pub = Pub
- data Sub = Sub
- data Surveyor = Surveyor
- data Respondent = Respondent
- data Push = Push
- data Pull = Pull
- data Bus = Bus
- data Socket a
- data Endpoint
- data NNException
- class SocketType a
- class SocketType a => Sender a
- class SocketType a => Receiver a
- socket :: SocketType a => a -> IO (Socket a)
- withSocket :: SocketType a => a -> (Socket a -> IO b) -> IO b
- bind :: Socket a -> String -> IO Endpoint
- connect :: Socket a -> String -> IO Endpoint
- send :: (Sender s, Binary dat) => Socket s -> dat -> IO ()
- recv :: (Receiver s, Binary dat) => Socket s -> IO dat
- recv' :: (Receiver s, Binary dat) => Socket s -> IO (Maybe dat)
- subscribe :: Socket Sub -> ByteString -> IO ()
- unsubscribe :: Socket Sub -> ByteString -> IO ()
- shutdown :: Socket a -> Endpoint -> IO ()
- close :: Socket a -> IO ()
- term :: IO ()
- linger :: Socket a -> IO Int
- setLinger :: Socket a -> Int -> IO ()
- sndBuf :: Socket a -> IO Int
- setSndBuf :: Socket a -> Int -> IO ()
- rcvBuf :: Socket a -> IO Int
- setRcvBuf :: Socket a -> Int -> IO ()
- reconnectInterval :: Socket a -> IO Int
- setReconnectInterval :: Socket a -> Int -> IO ()
- reconnectIntervalMax :: Socket a -> IO Int
- setReconnectIntervalMax :: Socket a -> Int -> IO ()
- sndPrio :: Socket a -> IO Int
- setSndPrio :: Socket a -> Int -> IO ()
- ipv4Only :: Socket a -> IO Int
- setIpv4Only :: Socket a -> Int -> IO ()
- requestResendInterval :: Socket Req -> IO Int
- setRequestResendInterval :: Socket Req -> Int -> IO ()
- surveyorDeadline :: Socket Surveyor -> IO Int
- setSurveyorDeadline :: Socket Surveyor -> Int -> IO ()
- tcpNoDelay :: Socket a -> IO Int
- setTcpNoDelay :: Socket a -> Int -> IO ()
Types
Socket types
Socket for communication with exactly one peer. Each party can send messages at any time. If the peer is not available or the send buffer is full, subsequent calls will block until it’s possible to send the message.
Request socket. Pairs with Rep
sockets.
The socket will resend requests automatically if there's no reply within a given time. The default timeout is 1 minute.
See also Rep
, setRequestResendInterval
.
Reply socket.
See also Req
.
Publish socket. Pairs with subscribe sockets.
See also Sub
.
Subscribe socket.
Only messages that the socket is subscribed to are received. When the socket is created there are no subscriptions and thus no messages will be received.
See also Pub
, subscribe
and unsubscribe
.
Surveyor and respondent are used to broadcast a survey to multiple locations and gather the responses.
This socket is used to send a survey. The survey is delivered to all onnected respondents. Once the query is sent, the socket can be used to receive the responses.
When the survey deadline expires, receive will throw an NNException.
See also Respondent
, setSurveyorDeadline
.
data Respondent Source #
Used to respond to a survey. Survey is received using receive, response is sent using send. This socket can be connected to at most one peer.
See also Surveyor
.
Instances
Receiver Respondent Source # | |
Defined in Nanomsg | |
Sender Respondent Source # | |
Defined in Nanomsg | |
SocketType Respondent Source # | |
Defined in Nanomsg socketType :: Respondent -> CInt |
Push and Pull sockets fair queue messages from one processing step, load balancing them among instances of the next processing step.
See also Pull
.
Pull socket.
See also Push
.
Broadcasts messages from any node to all other nodes in the topology. The socket should never receives messages that it sent itself.
Other
data NNException Source #
Pretty much any error condition throws this exception.
Instances
Eq NNException Source # | |
Defined in Nanomsg (==) :: NNException -> NNException -> Bool # (/=) :: NNException -> NNException -> Bool # | |
Show NNException Source # | |
Defined in Nanomsg showsPrec :: Int -> NNException -> ShowS # show :: NNException -> String # showList :: [NNException] -> ShowS # | |
Exception NNException Source # | |
Defined in Nanomsg |
class SocketType a Source #
Typeclass for all sockets
socketType
Instances
SocketType Bus Source # | |
Defined in Nanomsg socketType :: Bus -> CInt | |
SocketType Pull Source # | |
Defined in Nanomsg socketType :: Pull -> CInt | |
SocketType Push Source # | |
Defined in Nanomsg socketType :: Push -> CInt | |
SocketType Respondent Source # | |
Defined in Nanomsg socketType :: Respondent -> CInt | |
SocketType Surveyor Source # | |
Defined in Nanomsg socketType :: Surveyor -> CInt | |
SocketType Sub Source # | |
Defined in Nanomsg socketType :: Sub -> CInt | |
SocketType Pub Source # | |
Defined in Nanomsg socketType :: Pub -> CInt | |
SocketType Rep Source # | |
Defined in Nanomsg socketType :: Rep -> CInt | |
SocketType Req Source # | |
Defined in Nanomsg socketType :: Req -> CInt | |
SocketType Pair Source # | |
Defined in Nanomsg socketType :: Pair -> CInt |
class SocketType a => Sender a Source #
Typeclass restricting which sockets can use the send function.
Instances
Sender Bus Source # | |
Defined in Nanomsg | |
Sender Push Source # | |
Defined in Nanomsg | |
Sender Respondent Source # | |
Defined in Nanomsg | |
Sender Surveyor Source # | |
Defined in Nanomsg | |
Sender Pub Source # | |
Defined in Nanomsg | |
Sender Rep Source # | |
Defined in Nanomsg | |
Sender Req Source # | |
Defined in Nanomsg | |
Sender Pair Source # | |
Defined in Nanomsg |
class SocketType a => Receiver a Source #
Typeclass for sockets that implement recv
Instances
Receiver Bus Source # | |
Defined in Nanomsg | |
Receiver Pull Source # | |
Defined in Nanomsg | |
Receiver Respondent Source # | |
Defined in Nanomsg | |
Receiver Surveyor Source # | |
Defined in Nanomsg | |
Receiver Sub Source # | |
Defined in Nanomsg | |
Receiver Rep Source # | |
Defined in Nanomsg | |
Receiver Req Source # | |
Defined in Nanomsg | |
Receiver Pair Source # | |
Defined in Nanomsg |
Operations
General operations
withSocket :: SocketType a => a -> (Socket a -> IO b) -> IO b Source #
Creates a socket and runs your action with it.
E.g. collecting 10 messages:
withSocket Sub $ \sub -> do _ <- connect sub "tcp://localhost:5560" subscribe sub (C.pack "") replicateM 10 (recv sub)
Ensures the socket is closed when your action is done.
bind :: Socket a -> String -> IO Endpoint Source #
Binds the socket to a local interface.
See the nanomsg documentation for specifics on transports. Note that host names do not work for tcp. Some examples are:
bind sock "tcp://*:5560" bind sock "tcp://eth0:5560" bind sock "tcp://127.0.0.1:5560" bind sock "inproc://test" bind sock "ipc:///tmp/test.ipc"
This function returns an Endpoint
, which can be supplied
to shutdown
to remove a connection.
unsubscribe :: Socket Sub -> ByteString -> IO () Source #
Unsubscribes from a subject.
close :: Socket a -> IO () Source #
Closes the socket. Any buffered inbound messages that were not yet received by the application will be discarded. The library will try to deliver any outstanding outbound messages for the time specified by NN_LINGER socket option. The call will block in the meantime.
Switches nanomsg into shutdown modus and interrupts any waiting function calls.
Socket option settings
linger :: Socket a -> IO Int Source #
Specifies how long the socket should try to send pending outbound messages after close has been called, in milliseconds.
Negative value means infinite linger. Default value is 1000 (1 second).
setLinger :: Socket a -> Int -> IO () Source #
Specifies how long should the socket try to send pending outbound messages after close has been called, in milliseconds.
Negative value means infinite linger. Default value is 1000 (1 second).
sndBuf :: Socket a -> IO Int Source #
Size of the send buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the send buffer.
Default value is 128kB.
setSndBuf :: Socket a -> Int -> IO () Source #
Size of the send buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the send buffer.
Default value is 128kB.
rcvBuf :: Socket a -> IO Int Source #
Size of the receive buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the receive buffer.
Default value is 128kB.
setRcvBuf :: Socket a -> Int -> IO () Source #
Size of the receive buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the receive buffer.
Default value is 128kB.
reconnectInterval :: Socket a -> IO Int Source #
For connection-based transports such as TCP, this option specifies how long to wait, in milliseconds, when connection is broken before trying to re-establish it.
Note that actual reconnect interval may be randomised to some extent to prevent severe reconnection storms.
Default value is 100 (0.1 second).
setReconnectInterval :: Socket a -> Int -> IO () Source #
For connection-based transports such as TCP, this option specifies how long to wait, in milliseconds, when connection is broken before trying to re-establish it.
Note that actual reconnect interval may be randomised to some extent to prevent severe reconnection storms.
Default value is 100 (0.1 second).
reconnectIntervalMax :: Socket a -> IO Int Source #
This option is to be used only in addition to NN_RECONNECT_IVL option. It specifies maximum reconnection interval. On each reconnect attempt, the previous interval is doubled until NN_RECONNECT_IVL_MAX is reached.
Value of zero means that no exponential backoff is performed and reconnect interval is based only on NN_RECONNECT_IVL. If NN_RECONNECT_IVL_MAX is less than NN_RECONNECT_IVL, it is ignored.
Default value is 0.
setReconnectIntervalMax :: Socket a -> Int -> IO () Source #
This option is to be used only in addition to NN_RECONNECT_IVL option. It specifies maximum reconnection interval. On each reconnect attempt, the previous interval is doubled until NN_RECONNECT_IVL_MAX is reached.
Value of zero means that no exponential backoff is performed and reconnect interval is based only on NN_RECONNECT_IVL. If NN_RECONNECT_IVL_MAX is less than NN_RECONNECT_IVL, it is ignored.
Default value is 0.
sndPrio :: Socket a -> IO Int Source #
Sets outbound priority for endpoints subsequently added to the socket. This option has no effect on socket types that send messages to all the peers. However, if the socket type sends each message to a single peer (or a limited set of peers), peers with high priority take precedence over peers with low priority.
Highest priority is 1, lowest priority is 16. Default value is 8.
setSndPrio :: Socket a -> Int -> IO () Source #
Sets outbound priority for endpoints subsequently added to the socket. This option has no effect on socket types that send messages to all the peers. However, if the socket type sends each message to a single peer (or a limited set of peers), peers with high priority take precedence over peers with low priority.
Highest priority is 1, lowest priority is 16. Default value is 8.
ipv4Only :: Socket a -> IO Int Source #
If set to 1, only IPv4 addresses are used. If set to 0, both IPv4 and IPv6 addresses are used.
Default value is 1.
setIpv4Only :: Socket a -> Int -> IO () Source #
If set to 1, only IPv4 addresses are used. If set to 0, both IPv4 and IPv6 addresses are used.
Default value is 1.
requestResendInterval :: Socket Req -> IO Int Source #
This option is defined on the full REQ socket. If reply is not received in specified amount of milliseconds, the request will be automatically resent.
Default value is 60000 (1 minute).
setRequestResendInterval :: Socket Req -> Int -> IO () Source #
This option is defined on the full REQ socket. If reply is not received in specified amount of milliseconds, the request will be automatically resent.
Default value is 60000 (1 minute).