1NN_SETSOCKOPT(3)                 nanomsg 1.1.5                NN_SETSOCKOPT(3)
2
3
4

NAME

6       nn_setsockopt - set a socket option
7

SYNOPSIS

9       #include <nanomsg/nn.h>
10
11       int nn_setsockopt (int s, int level, int option, const void *optval,
12       size_t optvallen);
13

DESCRIPTION

15       Sets the value of the option. The level argument specifies the protocol
16       level at which the option resides. For generic socket-level options use
17       NN_SOL_SOCKET level. For socket-type-specific options use socket type
18       for level argument (e.g. NN_SUB). For transport-specific options use ID
19       of the transport as the level argument (e.g. NN_TCP).
20
21       The new value is pointed to by optval argument. Size of the option is
22       specified by the optvallen argument.
23
24       <nanomsg/nn.h> header defines generic socket-level options
25       (NN_SOL_SOCKET level). The options are as follows:
26
27       NN_SNDBUF
28           Size of the send buffer, in bytes. To prevent blocking for messages
29           larger than the buffer, exactly one message may be buffered in
30           addition to the data in the send buffer. The type of this option is
31           int. Default value is 128kB.
32
33       NN_RCVBUF
34           Size of the receive buffer, in bytes. To prevent blocking for
35           messages larger than the buffer, exactly one message may be
36           buffered in addition to the data in the receive buffer. The type of
37           this option is int. Default value is 128kB.
38
39       NN_RCVMAXSIZE
40           Maximum message size that can be received, in bytes. Negative value
41           means that the received size is limited only by available
42           addressable memory. The type of this option is int. Default is
43           1024kB.
44
45       NN_SNDTIMEO
46           The timeout for send operation on the socket, in milliseconds. If
47           message cannot be sent within the specified timeout, ETIMEDOUT
48           error is returned. Negative value means infinite timeout. The type
49           of the option is int. Default value is -1.
50
51       NN_RCVTIMEO
52           The timeout for recv operation on the socket, in milliseconds. If
53           message cannot be received within the specified timeout, ETIMEDOUT
54           error is returned. Negative value means infinite timeout. The type
55           of the option is int. Default value is -1.
56
57       NN_RECONNECT_IVL
58           For connection-based transports such as TCP, this option specifies
59           how long to wait, in milliseconds, when connection is broken before
60           trying to re-establish it. Note that actual reconnect interval may
61           be randomised to some extent to prevent severe reconnection storms.
62           The type of the option is int. Default value is 100 (0.1 second).
63
64       NN_RECONNECT_IVL_MAX
65           This option is to be used only in addition to NN_RECONNECT_IVL
66           option. It specifies maximum reconnection interval. On each
67           reconnect attempt, the previous interval is doubled until
68           NN_RECONNECT_IVL_MAX is reached. Value of zero means that no
69           exponential backoff is performed and reconnect interval is based
70           only on NN_RECONNECT_IVL. If NN_RECONNECT_IVL_MAX is less than
71           NN_RECONNECT_IVL, it is ignored. The type of the option is int.
72           Default value is 0.
73
74       NN_SNDPRIO
75           Sets outbound priority for endpoints subsequently added to the
76           socket. This option has no effect on socket types that send
77           messages to all the peers. However, if the socket type sends each
78           message to a single peer (or a limited set of peers), peers with
79           high priority take precedence over peers with low priority. The
80           type of the option is int. Highest priority is 1, lowest priority
81           is 16. Default value is 8.
82
83       NN_RCVPRIO
84           Sets inbound priority for endpoints subsequently added to the
85           socket. This option has no effect on socket types that are not able
86           to receive messages. When receiving a message, messages from peer
87           with higher priority are received before messages from peer with
88           lower priority. The type of the option is int. Highest priority is
89           1, lowest priority is 16. Default value is 8.
90
91       NN_IPV4ONLY
92           If set to 1, only IPv4 addresses are used. If set to 0, both IPv4
93           and IPv6 addresses are used. The type of the option is int. Default
94           value is 1.
95
96       NN_SOCKET_NAME
97           Socket name for error reporting and statistics. The type of the
98           option is string. Default value is "socket.N" where N is socket
99           integer. This option is experimental, see nn_env(7) for details
100
101       NN_MAXTTL
102           Sets the maximum number of "hops" a message can go through before
103           it is dropped. Each time the message is received (for example via
104           the nn_device(3) function) counts as a single hop. This provides a
105           form of protection against inadvertent loops.
106
107       NN_LINGER
108           This option is not implemented, and should not be used in new code.
109           Applications which need to be sure that their messages are
110           delivered to a remote peer should either use an acknowledgement
111           (implied when receiving a reply on NN_REQ sockets), or insert a
112           suitable delay before calling nn_close(3) or exiting the
113           application.
114

RETURN VALUE

116       If the function succeeds zero is returned. Otherwise, -1 is returned
117       and errno is set to to one of the values defined below.
118

ERRORS

120       EBADF
121           The provided socket is invalid.
122
123       ENOPROTOOPT
124           The option is unknown at the level indicated.
125
126       EINVAL
127           The specified option value is invalid.
128
129       ETERM
130           The library is terminating.
131

EXAMPLE

133           int linger = 1000;
134           nn_setsockopt (s, NN_SOL_SOCKET, NN_LINGER, &amp;linger, sizeof (linger));
135           nn_setsockopt (s, NN_SUB, NN_SUB_SUBSCRIBE, "ABC", 3);
136

SEE ALSO

138       nn_socket(3) nn_getsockopt(3) nanomsg(7)
139

AUTHORS

141       Martin Sustrik <sustrik@250bpm.com> Garrett D’Amore
142       <garrett@damore.org>
143
144
145
146                                  2018-10-15                  NN_SETSOCKOPT(3)
Impressum