NN_SETSOCKOPT(3)
π NN_SETSOCKOPT(3) β like, the nanomsg page for setting socket options π
okay bestie, gather round π«Ά this is the nn_setsockopt page from the nanomsg manual (that's the nanomsg 1.2.2 manual, section 3, iykyk) β it's the one that tells your socket how to be. β¨
πΈ NAME πΈ
nn_setsockopt β set a socket option. that's it, that's the whole vibe. π
π SYNOPSIS π
#include <nanomsg/nn.h>
int nn_setsockopt (int s, int level, int option, const void *optval,
size_t optvallen);
β¨ DESCRIPTION β¨
So basically: it sets the value of the option. π
The level argument says which protocol level the option lives at, and this part actually matters so pay attention bestie:
- For generic socket-level options, use the
NN_SOL_SOCKETlevel. - For socket-type-specific options, use the socket type as the
levelargument (e.g.NN_SUB). - For transport-specific options, use the ID of the transport as the
levelargument (e.g.NN_TCP).
The new value is pointed to by optval, and the size of the option is given by optvallen. π―
The <nanomsg/nn.h> header defines the generic socket-level options (that's the NN_SOL_SOCKET level, keep up π). The options are as follows:
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. Type isint. Default value is128kB. π§Ί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. Type isint. Default value is128kB. π§ΊNN_RCVMAXSIZEβ maximum message size that can be received, in bytes. A negative value means the received size is limited only by available addressable memory. Type isint. Default is1024kB. πNN_SNDTIMEOβ the timeout for send operation on the socket, in milliseconds. If the message cannot be sent within the specified timeout, anETIMEDOUTerror is returned. A negative value means infinite timeout. Type isint. Default value is-1. β³NN_RCVTIMEOβ the timeout for recv operation on the socket, in milliseconds. If the message cannot be received within the specified timeout, anETIMEDOUTerror is returned. A negative value means infinite timeout. Type isint. Default value is-1. β³NN_RECONNECT_IVLβ for connection-based transports such as TCP, this one specifies how long to wait, in milliseconds, when a connection is broken before trying to re-establish it. Note that the actual reconnect interval may be randomised to some extent to prevent severe reconnection storms. πͺοΈ Type isint. Default value is100(that's 0.1 second).NN_RECONNECT_IVL_MAXβ this option is to be used only in addition to theNN_RECONNECT_IVLoption. It specifies the maximum reconnection interval. On each reconnect attempt, the previous interval is doubled untilNN_RECONNECT_IVL_MAXis reached. A value of zero means no exponential backoff is performed and the reconnect interval is based only onNN_RECONNECT_IVL. IfNN_RECONNECT_IVL_MAXis less thanNN_RECONNECT_IVL, it is ignored. Type isint. Default value is0. π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. But 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. Type isint. Highest priority is1, lowest priority is16. Default value is8. πNN_RCVPRIOβ sets inbound priority for endpoints subsequently added to the socket. This option has no effect on socket types that are not able to receive messages. When receiving a message, messages from a peer with higher priority are received before messages from a peer with lower priority. Type isint. Highest priority is1, lowest priority is16. Default value is8. πNN_IPV4ONLYβ if set to1, only IPv4 addresses are used. If set to0, both IPv4 and IPv6 addresses are used. Type isint. Default value is1. πNN_SOCKET_NAMEβ socket name for error reporting and statistics. Type isstring. Default value is"socket.N"whereNis the socket integer. π·οΈ This option is experimental, seenn_env(7)for details.NN_MAXTTLβ sets the maximum number of "hops" a message can go through before it is dropped. Each time the message is received (for example via thenn_device(3)function) counts as a single hop. This provides a form of protection against inadvertent loops. πNN_LINGERβ > π¨ bestie no π¨ this option is not implemented, and should not be used in new code. Applications which need to be sure that their messages are delivered to a remote peer should either use an acknowledgement (implied when receiving a reply onNN_REQsockets), or insert a suitable delay before callingnn_close(3)or exiting the application. π
π RETURN VALUE π
If the function succeeds, zero is returned. π₯³ Otherwise, -1 is returned and errno is set 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 π¦
okay so here's the little snippet, look at her go:
int linger = 1000;
nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &linger, sizeof (linger));
nn_setsockopt (s, NN_SUB, NN_SUB_SUBSCRIBE, "ABC", 3);
(yes bestie, NN_LINGER is right there in the example even though it's not implemented β that's just what the page says, don't come for me π)
π SEE ALSO π
π AUTHORS π
Martin Sustrik <sustrik@250bpm.com> and Garrett DβAmore <garrett@damore.org> β absolute icons, we stan. π«Ά
and that's the whole page, bestie!! β¨ this was nanomsg 1.2.2, dated 2026-01-16, page NN_SETSOCKOPT(3). slay, go set some options, and remember: read your return values, periodt. π ππ¦
π¦ where this page comes from
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- fedora 44: nanomsg-devel 1.2.2-2.fc44 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms