nanomsg-haskell-0.2.4: Bindings to the nanomsg library

Safe HaskellNone
LanguageHaskell2010

Nanomsg.Binary

Contents

Description

This module offers a thin serialization layer (Binary based) over send and receive. You just need to import Nanomsg.Binary instead of Nanomsg.

Synopsis

Types

Socket types

data Pair Source #

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.

Constructors

Pair 
Instances
Receiver Pair Source # 
Instance details

Defined in Nanomsg

Sender Pair Source # 
Instance details

Defined in Nanomsg

SocketType Pair Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Pair -> CInt

data Req Source #

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.

Constructors

Req 
Instances
Receiver Req Source # 
Instance details

Defined in Nanomsg

Sender Req Source # 
Instance details

Defined in Nanomsg

SocketType Req Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Req -> CInt

data Rep Source #

Reply socket.

See also Req.

Constructors

Rep 
Instances
Receiver Rep Source # 
Instance details

Defined in Nanomsg

Sender Rep Source # 
Instance details

Defined in Nanomsg

SocketType Rep Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Rep -> CInt

data Pub Source #

Publish socket. Pairs with subscribe sockets.

See also Sub.

Constructors

Pub 
Instances
Sender Pub Source # 
Instance details

Defined in Nanomsg

SocketType Pub Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Pub -> CInt

data Sub Source #

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.

Constructors

Sub 
Instances
Receiver Sub Source # 
Instance details

Defined in Nanomsg

SocketType Sub Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Sub -> CInt

data Surveyor Source #

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.

Constructors

Surveyor 
Instances
Receiver Surveyor Source # 
Instance details

Defined in Nanomsg

Sender Surveyor Source # 
Instance details

Defined in Nanomsg

SocketType Surveyor Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Surveyor -> CInt

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.

Constructors

Respondent 
Instances
Receiver Respondent Source # 
Instance details

Defined in Nanomsg

Sender Respondent Source # 
Instance details

Defined in Nanomsg

SocketType Respondent Source # 
Instance details

Defined in Nanomsg

data Push Source #

Push and Pull sockets fair queue messages from one processing step, load balancing them among instances of the next processing step.

See also Pull.

Constructors

Push 
Instances
Sender Push Source # 
Instance details

Defined in Nanomsg

SocketType Push Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Push -> CInt

data Pull Source #

Pull socket.

See also Push.

Constructors

Pull 
Instances
Receiver Pull Source # 
Instance details

Defined in Nanomsg

SocketType Pull Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Pull -> CInt

data Bus Source #

Broadcasts messages from any node to all other nodes in the topology. The socket should never receives messages that it sent itself.

Constructors

Bus 
Instances
Receiver Bus Source # 
Instance details

Defined in Nanomsg

Sender Bus Source # 
Instance details

Defined in Nanomsg

SocketType Bus Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Bus -> CInt

Other

data Socket a Source #

Sockets are created by socket and connections are established with connect or bind.

Free sockets using close.

Instances
Eq a => Eq (Socket a) Source # 
Instance details

Defined in Nanomsg

Methods

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

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

Show a => Show (Socket a) Source # 
Instance details

Defined in Nanomsg

Methods

showsPrec :: Int -> Socket a -> ShowS #

show :: Socket a -> String #

showList :: [Socket a] -> ShowS #

data Endpoint Source #

Endpoint identifier. Created by connect or bind.

Close connections using shutdown.

Instances
Eq Endpoint Source # 
Instance details

Defined in Nanomsg

Show Endpoint Source # 
Instance details

Defined in Nanomsg

data NNException Source #

Pretty much any error condition throws this exception.

class SocketType a Source #

Typeclass for all sockets

Minimal complete definition

socketType

Instances
SocketType Bus Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Bus -> CInt

SocketType Pull Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Pull -> CInt

SocketType Push Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Push -> CInt

SocketType Respondent Source # 
Instance details

Defined in Nanomsg

SocketType Surveyor Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Surveyor -> CInt

SocketType Sub Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Sub -> CInt

SocketType Pub Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Pub -> CInt

SocketType Rep Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Rep -> CInt

SocketType Req Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Req -> CInt

SocketType Pair Source # 
Instance details

Defined in Nanomsg

Methods

socketType :: Pair -> CInt

class SocketType a => Sender a Source #

Typeclass restricting which sockets can use the send function.

Instances
Sender Bus Source # 
Instance details

Defined in Nanomsg

Sender Push Source # 
Instance details

Defined in Nanomsg

Sender Respondent Source # 
Instance details

Defined in Nanomsg

Sender Surveyor Source # 
Instance details

Defined in Nanomsg

Sender Pub Source # 
Instance details

Defined in Nanomsg

Sender Rep Source # 
Instance details

Defined in Nanomsg

Sender Req Source # 
Instance details

Defined in Nanomsg

Sender Pair Source # 
Instance details

Defined in Nanomsg

class SocketType a => Receiver a Source #

Typeclass for sockets that implement recv

Instances
Receiver Bus Source # 
Instance details

Defined in Nanomsg

Receiver Pull Source # 
Instance details

Defined in Nanomsg

Receiver Respondent Source # 
Instance details

Defined in Nanomsg

Receiver Surveyor Source # 
Instance details

Defined in Nanomsg

Receiver Sub Source # 
Instance details

Defined in Nanomsg

Receiver Rep Source # 
Instance details

Defined in Nanomsg

Receiver Req Source # 
Instance details

Defined in Nanomsg

Receiver Pair Source # 
Instance details

Defined in Nanomsg

Operations

General operations

socket :: SocketType a => a -> IO (Socket a) Source #

Creates a socket. Connections are formed using bind or connect.

See also: close.

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.

See also: connect, shutdown.

connect :: Socket a -> String -> IO Endpoint Source #

Connects the socket to an endpoint.

e.g. :

connect sock "tcp://localhost:5560"
connect sock "inproc://test"

See also: bind, shutdown.

send :: (Sender s, Binary dat) => Socket s -> dat -> IO () Source #

recv :: (Receiver s, Binary dat) => Socket s -> IO dat Source #

recv' :: (Receiver s, Binary dat) => Socket s -> IO (Maybe dat) Source #

subscribe :: Socket Sub -> ByteString -> IO () Source #

Subscribe to a given subject string.

unsubscribe :: Socket Sub -> ByteString -> IO () Source #

Unsubscribes from a subject.

shutdown :: Socket a -> Endpoint -> IO () Source #

Removes an endpoint from a socket.

See also: bind, connect.

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.

term :: IO () Source #

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

surveyorDeadline :: Socket Surveyor -> IO Int Source #

Get timeout for Surveyor sockets

setSurveyorDeadline :: Socket Surveyor -> Int -> IO () Source #

Set timeout for Surveyor sockets

tcpNoDelay :: Socket a -> IO Int Source #

This option, when set to 1, disables Nagle's algorithm.

Default value is 0.

setTcpNoDelay :: Socket a -> Int -> IO () Source #

This option, when set to 1, disables Nagle's algorithm.

Default value is 0.