nn_setsockopt(3compat)
| NN_SETSOCKOPT(3compat) | NNG Reference Manual | NN_SETSOCKOPT(3compat) |
NAME
nn_setsockopt - set socket option (compatible API)
SYNOPSIS
#include <nanomsg/nn.h> int nn_setsockopt(int sock, int level, int option, const void *val, size_t sz);
DESCRIPTION
The nn_setsockopt() function sets a socket option on socket sock, affecting the behavior of the socket. The option set is determined by the level and option. The value of the option is set by val, and sz, which are pointers to the actual value and the size of the value, respectively.
Note
This function is provided for API
compatibility with legacy libnanomsg. Consider using the relevant
modern API instead.
The level determines whether the option is a generic socket option, or is transport-specific. The values possible for level are as follows:
NN_SOL_SOCKET
NN_IPC
NN_TCP
NN_WS
The following generic socket options are possible (all are of type int and thus size 4, unless otherwise indicated.)
NN_SNDBUF
Note
In NNG buffers are sized as a count of messages rather than
bytes, and so an attempt to estimate a conversion based upon a predetermined
message size of 1kB is made. The value supplied is rounded up to the nearest
value divisible by 1024, and then divided by 1024 to convert to a message
count. Applications that have unusual message sizes may wish to adjust the
value used here accordingly.
NN_RCVBUF
Note
The same caveats for NN_SNDBUF apply here as well.
NN_SNDTIMEO
NN_RCVTIMEO
NN_RCVMAXSIZE
NN_RECONNECT_IVL
NN_RECONNECT_IVL_MAX
NN_LINGER
Note
This option was unreliable in early releases of libnanomsg,
and
is unsupported in NNG and recent libnanomsg releases.
Applications needing assurance of message delivery should either include an
explicit notification (automatic with the NN_REQ
protocol) or allow sufficient time for the socket to drain before closing
the socket or exiting.
NN_SNDPRIO
NN_RCVPRIO
NN_IPV4ONLY
NN_SOCKET_NAME
NN_MAXTTL
Note
Not all protocols offer this protection, so care should still be
used
in configuring device forwarding.
The following option is available for NN_REQ sockets using the NN_REQ level:
NN_REQ_RESEND_IVL
The following options are available for NN_SUB sockets using the NN_SUB level:
NN_SUB_SUBSCRIBE
Tip
To receive all messages, subscribe to an empty topic (sz equal to zero).
NN_SUB_UNSUBSCRIBE
The following option is available for NN_SURVEYOR sockets using the NN_SURVEYOR level:
NN_SURVEYOR_DEADLINE
In addition, the following transport specific options are offered:
NN_IPC_SEC_ATTR
NN_IPC_OUTBUFSZ
NN_IPC_INBUFSZE
NN_TCP_NODELAY
NN_WS_MSG_TYPE
RETURN VALUES
This function returns zero on success, and -1 on failure.
ERRORS
EBADF
ENOMEM
ENOPROTOOPT
EINVAL
ETERM
EACCES
SEE ALSO
nng_socket(5), nn_close(3compat), nn_errno(3compat), nn_getsockopt(3compat), nng_compat(3compat), nng(7)
| 2026-05-29 |
