NN_SETSOCKOPT(3compat)
π NN_SETSOCKOPT(3compat) π
okay so bestie, welcome to the NNG Reference Manual page for NN_SETSOCKOPT(3compat) β yes, that manual name is folded in right here at the top, iconic behavior only β¨. This is the compatibility-API page, and weβre gonna get through every single detail together, no cap π«Ά.
π 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 πΈ
okay so nn_setsockopt() sets a socket option on socket sock, and it 100% affects the behavior of the socket. The option set is determined by 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. slay, thatβs the whole setup π
.
Note: This function is provided for API compatibility with legacy libnanomsg. Consider using the relevant modern API instead. like, respect the legacy era, but maybe donβt make it your whole personality bestie π¦
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β Generic socket option πNN_IPCβ Transport specific option for IPC.NN_TCPβ Transport specific option for TCP.NN_WSβ Transport specific option for WebSocket.
The following generic socket options are possible β all are of type int and thus size 4, unless otherwise indicated. clock that caveat, bestie β
NN_SNDBUFβ Send buffer size in bytes.
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 of1kBis made. The value supplied is rounded up to the nearest value divisible by1024, and then divided by1024to convert to a message count. Applications that have unusual message sizes may wish to adjust the value used here accordingly. math girlie behavior, but make it sockets π§
NN_RCVBUFβ Receive buffer size in bytes.
Note: The same caveats for NN_SNDBUF apply here as well. π
NN_SNDTIMEOβ Send time-out in milliseconds. Send operations will fail withETIMEDOUTif no message can be received after this many milliseconds have transpired since the operation was started. A value of-1means that no timeout is applied. β³NN_RCVTIMEOβ Receive time-out in milliseconds. Receive operations will fail withETIMEDOUTif no message can be received after this many milliseconds have transpired since the operation was started. A value of-1means that no timeout is applied. π°οΈNN_RCVMAXSIZEβ Maximum receive size in bytes. The socket will discard messages larger than this on receive. The default,1MB, is intended to prevent denial-of-service attacks. The value-1removes any limit. security girlie said not today π‘οΈNN_RECONNECT_IVLβ Reconnect interval in milliseconds. After an outgoing connection is closed or fails, the socket will automatically attempt to reconnect after this many milliseconds. This is the starting value for the time, and is used in the first reconnection attempt after a successful connection is made. The default is100. πNN_RECONNECT_IVL_MAXβ Maximum reconnect interval in milliseconds. Subsequent reconnection attempts after a failed attempt are made at exponentially increasing intervals (back-off), but the interval is capped by this value. If this value is smaller thanNN_RECONNECT_IVL, then no exponential back-off is performed, and each reconnect interval will be determined solely byNN_RECONNECT_IVL. The default is zero. πNN_LINGERβ This option is ignored, and exists only for compatibility.
Note: This option was unreliable in early releases oflibnanomsg, and is unsupported in NNG and recentlibnanomsgreleases. Applications needing assurance of message delivery should either include an explicit notification (automatic with theNN_REQprotocol) or allow sufficient time for the socket to drain before closing the socket or exiting. read that note twice, bestie, itβs giving important π¨
NN_SNDPRIOβ This option is not implemented at this time. πNN_RCVPRIOβ This option is not implemented at this time. πNN_IPV4ONLYβ This option is not implemented at this time. πNN_SOCKET_NAMEβ This option is a string, and represents the socket name. It can be changed to help with identifying different sockets with their different application-specific purposes. π·οΈNN_MAXTTLβ Maximum number of times a message may traverse devices or proxies. This value, if positive, provides some protection against forwarding loops in device chains.
Note: Not all protocols offer this protection, so care should still be used in configuring device forwarding. lowkey a loop-protection era, but not universally π
The following option is available for NN_REQ sockets using the NN_REQ level:
NN_REQ_RESEND_IVLβ Request retry interval in milliseconds. If anNN_REQsocket does not receive a reply to a request within this period of time, the socket will automatically resend the request. The default value is60000(one minute). β±οΈ
The following options are available for NN_SUB sockets using the NN_SUB level:
NN_SUB_SUBSCRIBEβ Subscription topic, forNN_SUBsockets. This sets a subscription topic. When a message from a publisher arrives, it is compared against all subscriptions. If the firstszbytes of the message are not identical toval, then the message is silently discarded.
Tip: To receive all messages, subscribe to an empty topic (sz equal to zero). the βsubscribe to everythingβ hack, iykyk π
NN_SUB_UNSUBSCRIBEβ Removes a subscription topic that was earlier established. βοΈ
The following option is available for NN_SURVEYOR sockets using the NN_SURVEYOR level:
NN_SURVEYOR_DEADLINEβ Survey deadline in milliseconds forNN_SURVEYORsockets. After sending a survey message, the socket will only accept responses from respondents for this long. Any responses arriving after this expires are silently discarded. π¬
In addition, the following transport specific options are offered:
NN_IPC_SEC_ATTRβ ThisNN_IPCoption is not supported at this time. πNN_IPC_OUTBUFSZβ ThisNN_IPCoption is not supported at this time. πNN_IPC_INBUFSZEβ ThisNN_IPCoption is not supported at this time. πNN_TCP_NODELAYβ ThisNN_TCPoption is not supported at this time. πNN_WS_MSG_TYPEβ ThisNN_WSoption is not supported at this time. π
π RETURN VALUES π
This function returns zero on success, and -1 on failure. simple, clean, main-character return values π
π ERRORS π
EBADFβ The socketsockis not an open socket.ENOMEMβ Insufficient memory is available.ENOPROTOOPTβ Theleveland/oroptionis invalid.EINVALβ Theoption, or the value passed, is invalid.ETERMβ The library is shutting down.EACCESβ The option cannot be changed.
π₯ SEE ALSO π₯
nng_socket(5), nn_close(3compat), nn_errno(3compat), nn_getsockopt(3compat), nng_compat(3compat), nng(7)
mwah π β this NN_SETSOCKOPT(3compat) page is from the NNG Reference Manual and dated 2026-01-13, and thatβs the whole cute little sign-off bestie πβ¨
π¦ where this page comes from
- alpine 3.24: nng-doc 1.11-r0 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms