nanomsg
Home Download Documentation Development Community Support
NOTE: This documentation is for version 0.3-beta-2 of nanomsg, but the latest released version is 1.1.5. Please see the documentation for 1.1.5 for the most up-to-date information.
nn_setsockopt(3)

SYNOPSIS

#include <nanomsg/nn.h>

int nn_setsockopt (int s, int level, int option, const void *optval, size_t optvallen);

DESCRIPTION

Sets the value of the option. The level argument specifies the protocol level at which the option resides. For generic socket-level options use NN_SOL_SOCKET level. For socket-type-specific options use socket type for level argument (e.g. NN_SUB). For transport-specific options use ID of the transport as the level argument (e.g. NN_TCP).

The new value is pointed to by optval argument. Size of the option is specified by the optvallen argument.

<nanomsg/nn.h> header defines generic socket-level options (NN_SOL_SOCKET level). The options are as follows:

NN_LINGER

Specifies how long should the socket try to send pending outbound messages after nn_close() have been called, in milliseconds. Negative value means infinite linger. The type of the option is int. Default value is 1000 (1 second).

NN_SNDBUF

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. The type of this option is int. Default value is 128kB.

NN_RCVBUF

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. The type of this option is int. Default value is 128kB.

NN_SNDTIMEO

The timeout for send operation on the socket, in milliseconds. If message cannot be sent within the specified timeout, EAGAIN error is returned. Negative value means infinite timeout. The type of the option is int. Default value is -1.

NN_RCVTIMEO

The timeout for recv operation on the socket, in milliseconds. If message cannot be received within the specified timeout, EAGAIN error is returned. Negative value means infinite timeout. The type of the option is int. Default value is -1.

NN_RECONNECT_IVL

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. The type of the option is int. Default value is 100 (0.1 second).

NN_RECONNECT_IVL_MAX

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. The type of the option is int. Default value is 0.

NN_SNDPRIO

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. The type of the option is int. Highest priority is 1, lowest priority is 16. Default value is 8.

NN_IPV4ONLY

If set to 1, only IPv4 addresses are used. If set to 0, both IPv4 and IPv6 addresses are used. The type of the option is int. Default value is 1.

NN_SOCKET_NAME

Socket name for error reporting and statistics. The type of the option is string. Default value is "socket.N" where N is socket integer. This option is experimental, see nn_env(7) for details

RETURN VALUE

If the function succeeds zero is returned. Otherwise, -1 is returned and errno is set to to one of the values defined below.

ERRORS

EBADF

The provided socket is invalid.

ENOPROTOOPT

The option is unknown at the level indicated.

EINVAL

The specified option value is invalid.

ETERM

The library is terminating.

EXAMPLE

int linger = 1000;
nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &linger, sizeof (linger));
nn_setsockopt (s, NN_SUB, NN_SUB_SUBSCRIBE, "ABC", 3);

SEE ALSO

AUTHORS

Martin Sustrik <sustrik@250bpm.com>


"nanomsg" is a trademark of Garrett D'Amore.