'\" t .\" Title: nn_setsockopt .\" Author: [see the "AUTHOR(S)" section] .\" Generator: Asciidoctor 2.0.20 .\" Date: 2024-02-21 .\" Manual: nanomsg 1.2.1 .\" Source: \ \& .\" Language: English .\" .TH "NN_SETSOCKOPT" "3" "2024-02-21" "\ \&" "nanomsg 1.2.1" .ie \n(.g .ds Aq \(aq .el .ds Aq ' .ss \n[.ss] 0 .nh .ad l .de URL \fI\\$2\fP <\\$1>\\$3 .. .als MTO URL .if \n[.g] \{\ . mso www.tmac . am URL . ad l . . . am MTO . ad l . . . LINKSTYLE blue R < > .\} .SH "NAME" nn_setsockopt \- set a socket option .SH "SYNOPSIS" .sp \fB#include \fP .sp \fBint nn_setsockopt (int \fIs\fP, int \fIlevel\fP, int \fIoption\fP, const void \fI*optval\fP, size_t \fIoptvallen\fP);\fP .SH "DESCRIPTION" .sp Sets the value of the \fIoption\fP. The \fIlevel\fP argument specifies the protocol level at which the option resides. For generic socket\-level options use \fINN_SOL_SOCKET\fP level. For socket\-type\-specific options use socket type for \fIlevel\fP argument (e.g. \fINN_SUB\fP). For transport\-specific options use ID of the transport as the \fIlevel\fP argument (e.g. \fINN_TCP\fP). .sp The new value is pointed to by \fIoptval\fP argument. Size of the option is specified by the \fIoptvallen\fP argument. .sp \fI\fP header defines generic socket\-level options (\fINN_SOL_SOCKET\fP level). The options are as follows: .sp \fBNN_SNDBUF\fP .RS 4 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. .RE .sp \fBNN_RCVBUF\fP .RS 4 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. .RE .sp \fBNN_RCVMAXSIZE\fP .RS 4 Maximum message size that can be received, in bytes. Negative value means that the received size is limited only by available addressable memory. The type of this option is int. Default is 1024kB. .RE .sp \fBNN_SNDTIMEO\fP .RS 4 The timeout for send operation on the socket, in milliseconds. If message cannot be sent within the specified timeout, ETIMEDOUT error is returned. Negative value means infinite timeout. The type of the option is int. Default value is \-1. .RE .sp \fBNN_RCVTIMEO\fP .RS 4 The timeout for recv operation on the socket, in milliseconds. If message cannot be received within the specified timeout, ETIMEDOUT error is returned. Negative value means infinite timeout. The type of the option is int. Default value is \-1. .RE .sp \fBNN_RECONNECT_IVL\fP .RS 4 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). .RE .sp \fBNN_RECONNECT_IVL_MAX\fP .RS 4 This option is to be used only in addition to \fINN_RECONNECT_IVL\fP option. It specifies maximum reconnection interval. On each reconnect attempt, the previous interval is doubled until \fINN_RECONNECT_IVL_MAX\fP is reached. Value of zero means that no exponential backoff is performed and reconnect interval is based only on \fINN_RECONNECT_IVL\fP. If \fINN_RECONNECT_IVL_MAX\fP is less than \fINN_RECONNECT_IVL\fP, it is ignored. The type of the option is int. Default value is 0. .RE .sp \fBNN_SNDPRIO\fP .RS 4 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. .RE .sp \fBNN_RCVPRIO\fP .RS 4 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 peer with higher priority are received before messages from peer with lower priority. The type of the option is int. Highest priority is 1, lowest priority is 16. Default value is 8. .RE .sp \fBNN_IPV4ONLY\fP .RS 4 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. .RE .sp \fBNN_SOCKET_NAME\fP .RS 4 Socket name for error reporting and statistics. The type of the option is string. Default value is "socket.N" where N is socket integer. \fBThis option is experimental, see nn_env(7) for details\fP .RE .sp \fBNN_MAXTTL\fP .RS 4 Sets the maximum number of "hops" a message can go through before it is dropped. Each time the message is received (for example via the nn_device(3) function) counts as a single hop. This provides a form of protection against inadvertent loops. .RE .sp \fBNN_LINGER\fP .RS 4 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 on NN_REQ sockets), or insert a suitable delay before calling nn_close(3) or exiting the application. .RE .SH "RETURN VALUE" .sp If the function succeeds zero is returned. Otherwise, \-1 is returned and \fIerrno\fP is set to to one of the values defined below. .SH "ERRORS" .sp \fBEBADF\fP .RS 4 The provided socket is invalid. .RE .sp \fBENOPROTOOPT\fP .RS 4 The option is unknown at the level indicated. .RE .sp \fBEINVAL\fP .RS 4 The specified option value is invalid. .RE .sp \fBETERM\fP .RS 4 The library is terminating. .RE .SH "EXAMPLE" .sp .if n .RS 4 .nf .fam C int linger = 1000; nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &linger, sizeof (linger)); nn_setsockopt (s, NN_SUB, NN_SUB_SUBSCRIBE, "ABC", 3); .fam .fi .if n .RE .SH "SEE ALSO" .sp nn_socket(3) nn_getsockopt(3) nanomsg(7) .SH "AUTHORS" .sp \c .MTO "sustrik\(at250bpm.com" "Martin Sustrik" .MTO "garrett\(atdamore.org" "Garrett D\(cqAmore" ""