1ZMQ_SETSOCKOPT(3)                 0MQ Manual                 ZMQ_SETSOCKOPT(3)
2
3
4

NAME

6       zmq_setsockopt - set 0MQ socket options
7

SYNOPSIS

9       int zmq_setsockopt (void *socket, int option_name, const void
10       *option_value, size_t option_len);
11
12       Caution: All options, with the exception of ZMQ_SUBSCRIBE,
13       ZMQ_UNSUBSCRIBE and ZMQ_LINGER, only take effect for subsequent socket
14       bind/connects.
15

DESCRIPTION

17       The zmq_setsockopt() function shall set the option specified by the
18       option_name argument to the value pointed to by the option_value
19       argument for the 0MQ socket pointed to by the socket argument. The
20       option_len argument is the size of the option value in bytes.
21
22       The following socket options can be set with the zmq_setsockopt()
23       function:
24
25   ZMQ_HWM: Set high water mark
26       The ZMQ_HWM option shall set the high water mark for the specified
27       socket. The high water mark is a hard limit on the maximum number of
28       outstanding messages 0MQ shall queue in memory for any single peer that
29       the specified socket is communicating with.
30
31       If this limit has been reached the socket shall enter an exceptional
32       state and depending on the socket type, 0MQ shall take appropriate
33       action such as blocking or dropping sent messages. Refer to the
34       individual socket descriptions in zmq_socket(3) for details on the
35       exact action taken for each socket type.
36
37       The default ZMQ_HWM value of zero means "no limit".
38
39
40       Option value type         uint64_t
41
42       Option value unit         messages
43
44       Default value             0
45
46       Applicable socket types   all
47
48
49   ZMQ_SWAP: Set disk offload size
50       The ZMQ_SWAP option shall set the disk offload (swap) size for the
51       specified socket. A socket which has ZMQ_SWAP set to a non-zero value
52       may exceed it’s high water mark; in this case outstanding messages
53       shall be offloaded to storage on disk rather than held in memory.
54
55       The value of ZMQ_SWAP defines the maximum size of the swap space in
56       bytes.
57
58
59       Option value type         int64_t
60
61       Option value unit         bytes
62
63       Default value             0
64
65       Applicable socket types   all
66
67
68   ZMQ_AFFINITY: Set I/O thread affinity
69       The ZMQ_AFFINITY option shall set the I/O thread affinity for newly
70       created connections on the specified socket.
71
72       Affinity determines which threads from the 0MQ I/O thread pool
73       associated with the socket’s context shall handle newly created
74       connections. A value of zero specifies no affinity, meaning that work
75       shall be distributed fairly among all 0MQ I/O threads in the thread
76       pool. For non-zero values, the lowest bit corresponds to thread 1,
77       second lowest bit to thread 2 and so on. For example, a value of 3
78       specifies that subsequent connections on socket shall be handled
79       exclusively by I/O threads 1 and 2.
80
81       See also zmq_init(3) for details on allocating the number of I/O
82       threads for a specific context.
83
84
85       Option value type         uint64_t
86
87       Option value unit         N/A (bitmap)
88
89       Default value             0
90
91       Applicable socket types   N/A
92
93
94   ZMQ_IDENTITY: Set socket identity
95       The ZMQ_IDENTITY option shall set the identity of the specified socket.
96       Socket identity determines if existing 0MQ infrastructure (message
97       queues, forwarding devices) shall be identified with a specific
98       application and persist across multiple runs of the application.
99
100       If the socket has no identity, each run of an application is completely
101       separate from other runs. However, with identity set the socket shall
102       re-use any existing 0MQ infrastructure configured by the previous
103       run(s). Thus the application may receive messages that were sent in the
104       meantime, message queue limits shall be shared with previous run(s) and
105       so on.
106
107       Identity should be at least one byte and at most 255 bytes long.
108       Identities starting with binary zero are reserved for use by 0MQ
109       infrastructure.
110
111
112       Option value type         binary data
113
114       Option value unit         N/A
115
116       Default value             NULL
117
118       Applicable socket types   all
119
120
121   ZMQ_SUBSCRIBE: Establish message filter
122       The ZMQ_SUBSCRIBE option shall establish a new message filter on a
123       ZMQ_SUB socket. Newly created ZMQ_SUB sockets shall filter out all
124       incoming messages, therefore you should call this option to establish
125       an initial message filter.
126
127       An empty option_value of length zero shall subscribe to all incoming
128       messages. A non-empty option_value shall subscribe to all messages
129       beginning with the specified prefix. Multiple filters may be attached
130       to a single ZMQ_SUB socket, in which case a message shall be accepted
131       if it matches at least one filter.
132
133
134       Option value type         binary data
135
136       Option value unit         N/A
137
138       Default value             N/A
139
140       Applicable socket types   ZMQ_SUB
141
142
143   ZMQ_UNSUBSCRIBE: Remove message filter
144       The ZMQ_UNSUBSCRIBE option shall remove an existing message filter on a
145       ZMQ_SUB socket. The filter specified must match an existing filter
146       previously established with the ZMQ_SUBSCRIBE option. If the socket has
147       several instances of the same filter attached the ZMQ_UNSUBSCRIBE
148       option shall remove only one instance, leaving the rest in place and
149       functional.
150
151
152       Option value type         binary data
153
154       Option value unit         N/A
155
156       Default value             N/A
157
158       Applicable socket types   ZMQ_SUB
159
160
161   ZMQ_RATE: Set multicast data rate
162       The ZMQ_RATE option shall set the maximum send or receive data rate for
163       multicast transports such as zmq_pgm(7) using the specified socket.
164
165
166       Option value type         int64_t
167
168       Option value unit         kilobits per second
169
170       Default value             100
171
172       Applicable socket types   all, when using multicast
173                                 transports
174
175
176   ZMQ_RECOVERY_IVL: Set multicast recovery interval
177       The ZMQ_RECOVERY_IVL option shall set the recovery interval for
178       multicast transports using the specified socket. The recovery interval
179       determines the maximum time in seconds that a receiver can be absent
180       from a multicast group before unrecoverable data loss will occur.
181
182           Caution
183           Exercise care when setting large recovery intervals as the data
184           needed for recovery will be held in memory. For example, a 1 minute
185           recovery interval at a data rate of 1Gbps requires a 7GB in-memory
186           buffer.
187
188
189       Option value type         int64_t
190
191       Option value unit         seconds
192
193       Default value             10
194
195       Applicable socket types   all, when using multicast
196                                 transports
197
198
199   ZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds
200       The ZMQ_RECOVERY_IVL_MSEC option shall set the recovery interval,
201       specified in milliseconds (ms) for multicast transports using the
202       specified socket. The recovery interval determines the maximum time in
203       milliseconds that a receiver can be absent from a multicast group
204       before unrecoverable data loss will occur.
205
206       A non-zero value of the ZMQ_RECOVERY_IVL_MSEC option will take
207       precedence over the ZMQ_RECOVERY_IVL option, but since the default for
208       the ZMQ_RECOVERY_IVL_MSEC is -1, the default is to use the
209       ZMQ_RECOVERY_IVL option value.
210
211           Caution
212           Exercise care when setting large recovery intervals as the data
213           needed for recovery will be held in memory. For example, a 1 minute
214           recovery interval at a data rate of 1Gbps requires a 7GB in-memory
215           buffer.
216
217
218       Option value type         int64_t
219
220       Option value unit         milliseconds
221
222       Default value             -1
223
224       Applicable socket types   all, when using multicast
225                                 transports
226
227
228   ZMQ_MCAST_LOOP: Control multicast loop-back
229       The ZMQ_MCAST_LOOP option shall control whether data sent via multicast
230       transports using the specified socket can also be received by the
231       sending host via loop-back. A value of zero disables the loop-back
232       functionality, while the default value of 1 enables the loop-back
233       functionality. Leaving multicast loop-back enabled when it is not
234       required can have a negative impact on performance. Where possible,
235       disable ZMQ_MCAST_LOOP in production environments.
236
237
238       Option value type         int64_t
239
240       Option value unit         boolean
241
242       Default value             1
243
244       Applicable socket types   all, when using multicast
245                                 transports
246
247
248   ZMQ_SNDBUF: Set kernel transmit buffer size
249       The ZMQ_SNDBUF option shall set the underlying kernel transmit buffer
250       size for the socket to the specified size in bytes. A value of zero
251       means leave the OS default unchanged. For details please refer to your
252       operating system documentation for the SO_SNDBUF socket option.
253
254
255       Option value type         uint64_t
256
257       Option value unit         bytes
258
259       Default value             0
260
261       Applicable socket types   all
262
263
264   ZMQ_RCVBUF: Set kernel receive buffer size
265       The ZMQ_RCVBUF option shall set the underlying kernel receive buffer
266       size for the socket to the specified size in bytes. A value of zero
267       means leave the OS default unchanged. For details refer to your
268       operating system documentation for the SO_RCVBUF socket option.
269
270
271       Option value type         uint64_t
272
273       Option value unit         bytes
274
275       Default value             0
276
277       Applicable socket types   all
278
279
280   ZMQ_LINGER: Set linger period for socket shutdown
281       The ZMQ_LINGER option shall set the linger period for the specified
282       socket. The linger period determines how long pending messages which
283       have yet to be sent to a peer shall linger in memory after a socket is
284       closed with zmq_close(3), and further affects the termination of the
285       socket’s context with zmq_term(3). The following outlines the different
286       behaviours:
287
288       ·   The default value of -1 specifies an infinite linger period.
289           Pending messages shall not be discarded after a call to
290           zmq_close(); attempting to terminate the socket’s context with
291           zmq_term() shall block until all pending messages have been sent to
292           a peer.
293
294       ·   The value of 0 specifies no linger period. Pending messages shall
295           be discarded immediately when the socket is closed with
296           zmq_close().
297
298       ·   Positive values specify an upper bound for the linger period in
299           milliseconds. Pending messages shall not be discarded after a call
300           to zmq_close(); attempting to terminate the socket’s context with
301           zmq_term() shall block until either all pending messages have been
302           sent to a peer, or the linger period expires, after which any
303           pending messages shall be discarded.
304
305           Option value type         int
306           Option value unit         milliseconds
307           Default value             -1 (infinite)
308           Applicable socket types   all
309
310
311   ZMQ_RECONNECT_IVL: Set reconnection interval
312       The ZMQ_RECONNECT_IVL option shall set the initial reconnection
313       interval for the specified socket. The reconnection interval is the
314       period 0MQ shall wait between attempts to reconnect disconnected peers
315       when using connection-oriented transports.
316
317           Note
318           The reconnection interval may be randomized by 0MQ to prevent
319           reconnection storms in topologies with a large number of peers per
320           socket.
321
322
323       Option value type         int
324
325       Option value unit         milliseconds
326
327       Default value             100
328
329       Applicable socket types   all, only for
330                                 connection-oriented
331                                 transports
332
333
334   ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval
335       The ZMQ_RECONNECT_IVL_MAX option shall set the maximum reconnection
336       interval for the specified socket. This is the maximum period 0MQ shall
337       wait between attempts to reconnect. On each reconnect attempt, the
338       previous interval shall be doubled untill ZMQ_RECONNECT_IVL_MAX is
339       reached. This allows for exponential backoff strategy. Default value
340       means no exponential backoff is performed and reconnect interval
341       calculations are only based on ZMQ_RECONNECT_IVL.
342
343           Note
344           Values less than ZMQ_RECONNECT_IVL will be ignored.
345
346
347       Option value type         int
348
349       Option value unit         milliseconds
350
351       Default value             0 (only use
352                                 ZMQ_RECONNECT_IVL)
353
354       Applicable socket types   all, only for
355                                 connection-oriented
356                                 transports
357
358
359   ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections
360       The ZMQ_BACKLOG option shall set the maximum length of the queue of
361       outstanding peer connections for the specified socket; this only
362       applies to connection-oriented transports. For details refer to your
363       operating system documentation for the listen function.
364
365
366       Option value type         int
367
368       Option value unit         connections
369
370       Default value             100
371
372       Applicable socket types   all, only for
373                                 connection-oriented
374                                 transports.
375
376

RETURN VALUE

378       The zmq_setsockopt() function shall return zero if successful.
379       Otherwise it shall return -1 and set errno to one of the values defined
380       below.
381

ERRORS

383       EINVAL
384           The requested option option_name is unknown, or the requested
385           option_len or option_value is invalid.
386
387       ETERM
388           The 0MQ context associated with the specified socket was
389           terminated.
390
391       EFAULT
392           The provided socket was not valid (NULL).
393
394       EINTR
395           The operation was interrupted by delivery of a signal.
396

EXAMPLE

398       Subscribing to messages on a ZMQ_SUB socket.
399
400           /* Subscribe to all messages */
401           rc = zmq_setsockopt (socket, ZMQ_SUBSCRIBE, "", 0);
402           assert (rc == 0);
403           /* Subscribe to messages prefixed with "ANIMALS.CATS" */
404           rc = zmq_setsockopt (socket, ZMQ_SUBSCRIBE, "ANIMALS.CATS", 12);
405
406       Setting I/O thread affinity.
407
408           int64_t affinity;
409           /* Incoming connections on TCP port 5555 shall be handled by I/O thread 1 */
410           affinity = 1;
411           rc = zmq_setsockopt (socket, ZMQ_AFFINITY, &affinity, sizeof affinity);
412           assert (rc);
413           rc = zmq_bind (socket, "tcp://lo:5555");
414           assert (rc);
415           /* Incoming connections on TCP port 5556 shall be handled by I/O thread 2 */
416           affinity = 2;
417           rc = zmq_setsockopt (socket, ZMQ_AFFINITY, &affinity, sizeof affinity);
418           assert (rc);
419           rc = zmq_bind (socket, "tcp://lo:5556");
420           assert (rc);
421
422

SEE ALSO

424       zmq_getsockopt(3) zmq_socket(3) zmq(7)
425

AUTHORS

427       This 0MQ manual page was written by Martin Sustrik
428       <sustrik@250bpm.com[1]> and Martin Lucina <mato@kotelna.sk[2]>.
429

NOTES

431        1. sustrik@250bpm.com
432           mailto:sustrik@250bpm.com
433
434        2. mato@kotelna.sk
435           mailto:mato@kotelna.sk
436
437
438
4390MQ 2.1.4                         03/30/2011                 ZMQ_SETSOCKOPT(3)
Impressum