NN_GETSOCKOPT(3compat)
NN_GETSOCKOPT(3compat) π
Okay bestie, this is the NN_GETSOCKOPT(3compat) page from the NNG Reference Manual, and itβs all about getting a socket option through the compat API. Buckle up, itβs giving βlegacy but still usefulβ energy β¨
πΈ NAME πΈ
nn_getsockopt β get socket option (compatible API)
β¨ SYNOPSIS β¨
#include <nanomsg/nn.h>
int nn_getsockopt(int sock, int level, int option, void *val, size_t *szp);
π DESCRIPTION π
The nn_getsockopt() function gets a socket option on socket sock. The option retrieved is determined by level and option. Literally the duo doing all the work π
Note: This function is provided for API compatibility with legacy libnanomsg. Consider using the relevant modern API instead.
The value pointed to by szp must be initialized to the size of the buffer pointed to by val. No more than this many bytes of the option will be copied into the destination buffer on success. On success, the value pointed to by szp will be updated with the actual size of the option. So yes, szp is doing double duty, and we respect her for it π«Ά
Tip: To determine the size to receive an option, first call this function withvalset toNULLand the value addressed byszpinitialized to zero.
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 optionNN_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.)
NN_SNDBUFβ Send buffer size in bytes.
Note: In NNG buffers are sized as a count of messages rather than bytes; accordingly this value is the queue depth multiplied by1024(representing an estimate that the average message size is1kB). Applications that have unusual message sizes may wish to adjust the value used here accordingly.
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.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 always zero 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.
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.
NN_DOMAINβ This option of typeintrepresents either the valueAF_SPorAF_SP_RAW, corresponding to the value that the socket was created with.NN_PROTOCOLβ This option option of typeintcontains the numeric protocol number that the socket is used with.NN_RCVFDβ This option returns a file descriptor suitable for use in withpoll()orselect()(or other system-specific polling functions). This descriptor will be readable when a message is available for receiving at the socket. This option is of typeinton all systems except Windows, where it is of typeSOCKET.
Note: The file descriptor should not be read or written by the application, and is not the same as any underlying descriptor used for network sockets.
NN_SNDFDβ This option returns a file descriptor suitable for use in withpoll()orselect()(or other system-specific polling functions). This descriptor will be readable when the socket is able to accept a message for sending. This option is of typeinton all systems except Windows, where it is of typeSOCKET.
Note: The file descriptor should not be read or written by the application, and is not the same as any underlying descriptor used for network sockets. Furthermore, the file descriptor should only be polled for readability.
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 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, as NNG only supports binary messages in this implementation.
π RETURN VALUES π
This function returns zero on success, and -1 on failure. Short, sweet, and very βdid it work or notβ of her π
π ERRORS π
EBADFβ The socketsockis not an open socket.ENOMEMβ Insufficient memory is available.ENOPROTOOPTβ Theleveland/oroptionis invalid.EINVALβ The option, or the value passed, is invalid.ETERMβ The library is shutting down.EACCESβ The option cannot be changed.
π¦ SEE ALSO π¦
Cute sign-off time, bestie: this is NN_GETSOCKOPT(3compat) from the NNG Reference Manual, dated 2026-01-13. Go forth and get those socket options, icon behavior only πβ¨π
π¦ 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