1ZSOCK(3)                          CZMQ Manual                         ZSOCK(3)
2
3
4

NAME

6       zsock - high-level socket API that hides libzmq contexts and sockets
7

SYNOPSIS

9       //  This is a stable class, and may not change except for emergencies. It
10       //  is provided in stable builds.
11       //  This class has draft methods, which may change over time. They are not
12       //  in stable releases, by default. Use --enable-drafts to enable.
13       //  Create a new socket. Returns the new socket, or NULL if the new socket
14       //  could not be created. Note that the symbol zsock_new (and other
15       //  constructors/destructors for zsock) are redirected to the *_checked
16       //  variant, enabling intelligent socket leak detection. This can have
17       //  performance implications if you use a LOT of sockets. To turn off this
18       //  redirection behaviour, define ZSOCK_NOCHECK.
19       CZMQ_EXPORT zsock_t *
20           zsock_new (int type);
21
22       //  Create a PUB socket. Default action is bind.
23       CZMQ_EXPORT zsock_t *
24           zsock_new_pub (const char *endpoint);
25
26       //  Create a SUB socket, and optionally subscribe to some prefix string. Default
27       //  action is connect.
28       CZMQ_EXPORT zsock_t *
29           zsock_new_sub (const char *endpoint, const char *subscribe);
30
31       //  Create a REQ socket. Default action is connect.
32       CZMQ_EXPORT zsock_t *
33           zsock_new_req (const char *endpoint);
34
35       //  Create a REP socket. Default action is bind.
36       CZMQ_EXPORT zsock_t *
37           zsock_new_rep (const char *endpoint);
38
39       //  Create a DEALER socket. Default action is connect.
40       CZMQ_EXPORT zsock_t *
41           zsock_new_dealer (const char *endpoint);
42
43       //  Create a ROUTER socket. Default action is bind.
44       CZMQ_EXPORT zsock_t *
45           zsock_new_router (const char *endpoint);
46
47       //  Create a PUSH socket. Default action is connect.
48       CZMQ_EXPORT zsock_t *
49           zsock_new_push (const char *endpoint);
50
51       //  Create a PULL socket. Default action is bind.
52       CZMQ_EXPORT zsock_t *
53           zsock_new_pull (const char *endpoint);
54
55       //  Create an XPUB socket. Default action is bind.
56       CZMQ_EXPORT zsock_t *
57           zsock_new_xpub (const char *endpoint);
58
59       //  Create an XSUB socket. Default action is connect.
60       CZMQ_EXPORT zsock_t *
61           zsock_new_xsub (const char *endpoint);
62
63       //  Create a PAIR socket. Default action is connect.
64       CZMQ_EXPORT zsock_t *
65           zsock_new_pair (const char *endpoint);
66
67       //  Create a STREAM socket. Default action is connect.
68       CZMQ_EXPORT zsock_t *
69           zsock_new_stream (const char *endpoint);
70
71       //  Destroy the socket. You must use this for any socket created via the
72       //  zsock_new method.
73       CZMQ_EXPORT void
74           zsock_destroy (zsock_t **self_p);
75
76       //  Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
77       //  ephemeral ports, if you specify the port number as "*". By default
78       //  zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
79       //  To override this range, follow the "*" with "[first-last]". Either or
80       //  both first and last may be empty. To bind to a random port within the
81       //  range, use "!" in place of "*".
82       //
83       //  Examples:
84       //      tcp://127.0.0.1:*           bind to first free port from C000 up
85       //      tcp://127.0.0.1:!           bind to random port from C000 to FFFF
86       //      tcp://127.0.0.1:*[60000-]   bind to first free port from 60000 up
87       //      tcp://127.0.0.1:![-60000]   bind to random port from C000 to 60000
88       //      tcp://127.0.0.1:![55000-55999]
89       //                                  bind to random port from 55000 to 55999
90       //
91       //  On success, returns the actual port number used, for tcp:// endpoints,
92       //  and 0 for other transports. On failure, returns -1. Note that when using
93       //  ephemeral ports, a port may be reused by different services without
94       //  clients being aware. Protocols that run on ephemeral ports should take
95       //  this into account.
96       CZMQ_EXPORT int
97           zsock_bind (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
98
99       //  Returns last bound endpoint, if any.
100       CZMQ_EXPORT const char *
101           zsock_endpoint (zsock_t *self);
102
103       //  Unbind a socket from a formatted endpoint.
104       //  Returns 0 if OK, -1 if the endpoint was invalid or the function
105       //  isn't supported.
106       CZMQ_EXPORT int
107           zsock_unbind (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
108
109       //  Connect a socket to a formatted endpoint
110       //  Returns 0 if OK, -1 if the endpoint was invalid.
111       CZMQ_EXPORT int
112           zsock_connect (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
113
114       //  Disconnect a socket from a formatted endpoint
115       //  Returns 0 if OK, -1 if the endpoint was invalid or the function
116       //  isn't supported.
117       CZMQ_EXPORT int
118           zsock_disconnect (zsock_t *self, const char *format, ...) CHECK_PRINTF (2);
119
120       //  Attach a socket to zero or more endpoints. If endpoints is not null,
121       //  parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
122       //  '@' (to bind the socket) or '>' (to connect the socket). Returns 0 if all
123       //  endpoints were valid, or -1 if there was a syntax error. If the endpoint
124       //  does not start with '@' or '>', the serverish argument defines whether
125       //  it is used to bind (serverish = true) or connect (serverish = false).
126       CZMQ_EXPORT int
127           zsock_attach (zsock_t *self, const char *endpoints, bool serverish);
128
129       //  Returns socket type as printable constant string.
130       CZMQ_EXPORT const char *
131           zsock_type_str (zsock_t *self);
132
133       //  Send a 'picture' message to the socket (or actor). The picture is a
134       //  string that defines the type of each frame. This makes it easy to send
135       //  a complex multiframe message in one call. The picture can contain any
136       //  of these characters, each corresponding to one or two arguments:
137       //
138       //      i = int (signed)
139       //      1 = uint8_t
140       //      2 = uint16_t
141       //      4 = uint32_t
142       //      8 = uint64_t
143       //      s = char *
144       //      b = byte *, size_t (2 arguments)
145       //      c = zchunk_t *
146       //      f = zframe_t *
147       //      h = zhashx_t *
148       //      U = zuuid_t *
149       //      p = void * (sends the pointer value, only meaningful over inproc)
150       //      m = zmsg_t * (sends all frames in the zmsg)
151       //      z = sends zero-sized frame (0 arguments)
152       //      u = uint (deprecated)
153       //
154       //  Note that s, b, c, and f are encoded the same way and the choice is
155       //  offered as a convenience to the sender, which may or may not already
156       //  have data in a zchunk or zframe. Does not change or take ownership of
157       //  any arguments. Returns 0 if successful, -1 if sending failed for any
158       //  reason.
159       CZMQ_EXPORT int
160           zsock_send (void *self, const char *picture, ...);
161
162       //  Send a 'picture' message to the socket (or actor). This is a va_list
163       //  version of zsock_send (), so please consult its documentation for the
164       //  details.
165       CZMQ_EXPORT int
166           zsock_vsend (void *self, const char *picture, va_list argptr);
167
168       //  Receive a 'picture' message to the socket (or actor). See zsock_send for
169       //  the format and meaning of the picture. Returns the picture elements into
170       //  a series of pointers as provided by the caller:
171       //
172       //      i = int * (stores signed integer)
173       //      4 = uint32_t * (stores 32-bit unsigned integer)
174       //      8 = uint64_t * (stores 64-bit unsigned integer)
175       //      s = char ** (allocates new string)
176       //      b = byte **, size_t * (2 arguments) (allocates memory)
177       //      c = zchunk_t ** (creates zchunk)
178       //      f = zframe_t ** (creates zframe)
179       //      U = zuuid_t * (creates a zuuid with the data)
180       //      h = zhashx_t ** (creates zhashx)
181       //      p = void ** (stores pointer)
182       //      m = zmsg_t ** (creates a zmsg with the remaing frames)
183       //      z = null, asserts empty frame (0 arguments)
184       //      u = uint * (stores unsigned integer, deprecated)
185       //
186       //  Note that zsock_recv creates the returned objects, and the caller must
187       //  destroy them when finished with them. The supplied pointers do not need
188       //  to be initialized. Returns 0 if successful, or -1 if it failed to recv
189       //  a message, in which case the pointers are not modified. When message
190       //  frames are truncated (a short message), sets return values to zero/null.
191       //  If an argument pointer is NULL, does not store any value (skips it).
192       //  An 'n' picture matches an empty frame; if the message does not match,
193       //  the method will return -1.
194       CZMQ_EXPORT int
195           zsock_recv (void *self, const char *picture, ...);
196
197       //  Receive a 'picture' message from the socket (or actor). This is a
198       //  va_list version of zsock_recv (), so please consult its documentation
199       //  for the details.
200       CZMQ_EXPORT int
201           zsock_vrecv (void *self, const char *picture, va_list argptr);
202
203       //  Send a binary encoded 'picture' message to the socket (or actor). This
204       //  method is similar to zsock_send, except the arguments are encoded in a
205       //  binary format that is compatible with zproto, and is designed to reduce
206       //  memory allocations. The pattern argument is a string that defines the
207       //  type of each argument. Supports these argument types:
208       //
209       //   pattern    C type                  zproto type:
210       //      1       uint8_t                 type = "number" size = "1"
211       //      2       uint16_t                type = "number" size = "2"
212       //      4       uint32_t                type = "number" size = "3"
213       //      8       uint64_t                type = "number" size = "4"
214       //      s       char *, 0-255 chars     type = "string"
215       //      S       char *, 0-2^32-1 chars  type = "longstr"
216       //      c       zchunk_t *              type = "chunk"
217       //      f       zframe_t *              type = "frame"
218       //      u       zuuid_t *               type = "uuid"
219       //      m       zmsg_t *                type = "msg"
220       //      p       void *, sends pointer value, only over inproc
221       //
222       //  Does not change or take ownership of any arguments. Returns 0 if
223       //  successful, -1 if sending failed for any reason.
224       CZMQ_EXPORT int
225           zsock_bsend (void *self, const char *picture, ...);
226
227       //  Receive a binary encoded 'picture' message from the socket (or actor).
228       //  This method is similar to zsock_recv, except the arguments are encoded
229       //  in a binary format that is compatible with zproto, and is designed to
230       //  reduce memory allocations. The pattern argument is a string that defines
231       //  the type of each argument. See zsock_bsend for the supported argument
232       //  types. All arguments must be pointers; this call sets them to point to
233       //  values held on a per-socket basis.
234       //  Note that zsock_brecv creates the returned objects, and the caller must
235       //  destroy them when finished with them. The supplied pointers do not need
236       //  to be initialized. Returns 0 if successful, or -1 if it failed to read
237       //  a message.
238       CZMQ_EXPORT int
239           zsock_brecv (void *self, const char *picture, ...);
240
241       //  Set socket to use unbounded pipes (HWM=0); use this in cases when you are
242       //  totally certain the message volume can fit in memory. This method works
243       //  across all versions of ZeroMQ. Takes a polymorphic socket reference.
244       CZMQ_EXPORT void
245           zsock_set_unbounded (void *self);
246
247       //  Send a signal over a socket. A signal is a short message carrying a
248       //  success/failure code (by convention, 0 means OK). Signals are encoded
249       //  to be distinguishable from "normal" messages. Accepts a zsock_t or a
250       //  zactor_t argument, and returns 0 if successful, -1 if the signal could
251       //  not be sent. Takes a polymorphic socket reference.
252       CZMQ_EXPORT int
253           zsock_signal (void *self, byte status);
254
255       //  Wait on a signal. Use this to coordinate between threads, over pipe
256       //  pairs. Blocks until the signal is received. Returns -1 on error, 0 or
257       //  greater on success. Accepts a zsock_t or a zactor_t as argument.
258       //  Takes a polymorphic socket reference.
259       CZMQ_EXPORT int
260           zsock_wait (void *self);
261
262       //  If there is a partial message still waiting on the socket, remove and
263       //  discard it. This is useful when reading partial messages, to get specific
264       //  message types.
265       CZMQ_EXPORT void
266           zsock_flush (void *self);
267
268       //  Probe the supplied object, and report if it looks like a zsock_t.
269       //  Takes a polymorphic socket reference.
270       CZMQ_EXPORT bool
271           zsock_is (void *self);
272
273       //  Probe the supplied reference. If it looks like a zsock_t instance, return
274       //  the underlying libzmq socket handle; else if it looks like a file
275       //  descriptor, return NULL; else if it looks like a libzmq socket handle,
276       //  return the supplied value. Takes a polymorphic socket reference.
277       CZMQ_EXPORT void *
278           zsock_resolve (void *self);
279
280       //  Get socket option `heartbeat_ivl`.
281       //  Available from libzmq 4.2.0.
282       //  Caller owns return value and must destroy it when done.
283       CZMQ_EXPORT int
284           zsock_heartbeat_ivl (void *self);
285
286       //  Set socket option `heartbeat_ivl`.
287       //  Available from libzmq 4.2.0.
288       CZMQ_EXPORT void
289           zsock_set_heartbeat_ivl (void *self, int heartbeat_ivl);
290
291       //  Get socket option `heartbeat_ttl`.
292       //  Available from libzmq 4.2.0.
293       //  Caller owns return value and must destroy it when done.
294       CZMQ_EXPORT int
295           zsock_heartbeat_ttl (void *self);
296
297       //  Set socket option `heartbeat_ttl`.
298       //  Available from libzmq 4.2.0.
299       CZMQ_EXPORT void
300           zsock_set_heartbeat_ttl (void *self, int heartbeat_ttl);
301
302       //  Get socket option `heartbeat_timeout`.
303       //  Available from libzmq 4.2.0.
304       //  Caller owns return value and must destroy it when done.
305       CZMQ_EXPORT int
306           zsock_heartbeat_timeout (void *self);
307
308       //  Set socket option `heartbeat_timeout`.
309       //  Available from libzmq 4.2.0.
310       CZMQ_EXPORT void
311           zsock_set_heartbeat_timeout (void *self, int heartbeat_timeout);
312
313       //  Get socket option `use_fd`.
314       //  Available from libzmq 4.2.0.
315       //  Caller owns return value and must destroy it when done.
316       CZMQ_EXPORT int
317           zsock_use_fd (void *self);
318
319       //  Set socket option `use_fd`.
320       //  Available from libzmq 4.2.0.
321       CZMQ_EXPORT void
322           zsock_set_use_fd (void *self, int use_fd);
323
324       //  Set socket option `xpub_manual`.
325       //  Available from libzmq 4.2.0.
326       CZMQ_EXPORT void
327           zsock_set_xpub_manual (void *self, int xpub_manual);
328
329       //  Set socket option `xpub_welcome_msg`.
330       //  Available from libzmq 4.2.0.
331       CZMQ_EXPORT void
332           zsock_set_xpub_welcome_msg (void *self, const char *xpub_welcome_msg);
333
334       //  Set socket option `stream_notify`.
335       //  Available from libzmq 4.2.0.
336       CZMQ_EXPORT void
337           zsock_set_stream_notify (void *self, int stream_notify);
338
339       //  Get socket option `invert_matching`.
340       //  Available from libzmq 4.2.0.
341       //  Caller owns return value and must destroy it when done.
342       CZMQ_EXPORT int
343           zsock_invert_matching (void *self);
344
345       //  Set socket option `invert_matching`.
346       //  Available from libzmq 4.2.0.
347       CZMQ_EXPORT void
348           zsock_set_invert_matching (void *self, int invert_matching);
349
350       //  Set socket option `xpub_verboser`.
351       //  Available from libzmq 4.2.0.
352       CZMQ_EXPORT void
353           zsock_set_xpub_verboser (void *self, int xpub_verboser);
354
355       //  Get socket option `connect_timeout`.
356       //  Available from libzmq 4.2.0.
357       //  Caller owns return value and must destroy it when done.
358       CZMQ_EXPORT int
359           zsock_connect_timeout (void *self);
360
361       //  Set socket option `connect_timeout`.
362       //  Available from libzmq 4.2.0.
363       CZMQ_EXPORT void
364           zsock_set_connect_timeout (void *self, int connect_timeout);
365
366       //  Get socket option `tcp_maxrt`.
367       //  Available from libzmq 4.2.0.
368       //  Caller owns return value and must destroy it when done.
369       CZMQ_EXPORT int
370           zsock_tcp_maxrt (void *self);
371
372       //  Set socket option `tcp_maxrt`.
373       //  Available from libzmq 4.2.0.
374       CZMQ_EXPORT void
375           zsock_set_tcp_maxrt (void *self, int tcp_maxrt);
376
377       //  Get socket option `thread_safe`.
378       //  Available from libzmq 4.2.0.
379       //  Caller owns return value and must destroy it when done.
380       CZMQ_EXPORT int
381           zsock_thread_safe (void *self);
382
383       //  Get socket option `multicast_maxtpdu`.
384       //  Available from libzmq 4.2.0.
385       //  Caller owns return value and must destroy it when done.
386       CZMQ_EXPORT int
387           zsock_multicast_maxtpdu (void *self);
388
389       //  Set socket option `multicast_maxtpdu`.
390       //  Available from libzmq 4.2.0.
391       CZMQ_EXPORT void
392           zsock_set_multicast_maxtpdu (void *self, int multicast_maxtpdu);
393
394       //  Get socket option `vmci_buffer_size`.
395       //  Available from libzmq 4.2.0.
396       //  Caller owns return value and must destroy it when done.
397       CZMQ_EXPORT int
398           zsock_vmci_buffer_size (void *self);
399
400       //  Set socket option `vmci_buffer_size`.
401       //  Available from libzmq 4.2.0.
402       CZMQ_EXPORT void
403           zsock_set_vmci_buffer_size (void *self, int vmci_buffer_size);
404
405       //  Get socket option `vmci_buffer_min_size`.
406       //  Available from libzmq 4.2.0.
407       //  Caller owns return value and must destroy it when done.
408       CZMQ_EXPORT int
409           zsock_vmci_buffer_min_size (void *self);
410
411       //  Set socket option `vmci_buffer_min_size`.
412       //  Available from libzmq 4.2.0.
413       CZMQ_EXPORT void
414           zsock_set_vmci_buffer_min_size (void *self, int vmci_buffer_min_size);
415
416       //  Get socket option `vmci_buffer_max_size`.
417       //  Available from libzmq 4.2.0.
418       //  Caller owns return value and must destroy it when done.
419       CZMQ_EXPORT int
420           zsock_vmci_buffer_max_size (void *self);
421
422       //  Set socket option `vmci_buffer_max_size`.
423       //  Available from libzmq 4.2.0.
424       CZMQ_EXPORT void
425           zsock_set_vmci_buffer_max_size (void *self, int vmci_buffer_max_size);
426
427       //  Get socket option `vmci_connect_timeout`.
428       //  Available from libzmq 4.2.0.
429       //  Caller owns return value and must destroy it when done.
430       CZMQ_EXPORT int
431           zsock_vmci_connect_timeout (void *self);
432
433       //  Set socket option `vmci_connect_timeout`.
434       //  Available from libzmq 4.2.0.
435       CZMQ_EXPORT void
436           zsock_set_vmci_connect_timeout (void *self, int vmci_connect_timeout);
437
438       //  Get socket option `tos`.
439       //  Available from libzmq 4.1.0.
440       //  Caller owns return value and must destroy it when done.
441       CZMQ_EXPORT int
442           zsock_tos (void *self);
443
444       //  Set socket option `tos`.
445       //  Available from libzmq 4.1.0.
446       CZMQ_EXPORT void
447           zsock_set_tos (void *self, int tos);
448
449       //  Set socket option `router_handover`.
450       //  Available from libzmq 4.1.0.
451       CZMQ_EXPORT void
452           zsock_set_router_handover (void *self, int router_handover);
453
454       //  Set socket option `connect_rid`.
455       //  Available from libzmq 4.1.0.
456       CZMQ_EXPORT void
457           zsock_set_connect_rid (void *self, const char *connect_rid);
458
459       //  Set socket option `connect_rid` from 32-octet binary
460       //  Available from libzmq 4.1.0.
461       CZMQ_EXPORT void
462           zsock_set_connect_rid_bin (void *self, const byte *connect_rid);
463
464       //  Get socket option `handshake_ivl`.
465       //  Available from libzmq 4.1.0.
466       //  Caller owns return value and must destroy it when done.
467       CZMQ_EXPORT int
468           zsock_handshake_ivl (void *self);
469
470       //  Set socket option `handshake_ivl`.
471       //  Available from libzmq 4.1.0.
472       CZMQ_EXPORT void
473           zsock_set_handshake_ivl (void *self, int handshake_ivl);
474
475       //  Get socket option `socks_proxy`.
476       //  Available from libzmq 4.1.0.
477       //  Caller owns return value and must destroy it when done.
478       CZMQ_EXPORT char *
479           zsock_socks_proxy (void *self);
480
481       //  Set socket option `socks_proxy`.
482       //  Available from libzmq 4.1.0.
483       CZMQ_EXPORT void
484           zsock_set_socks_proxy (void *self, const char *socks_proxy);
485
486       //  Set socket option `xpub_nodrop`.
487       //  Available from libzmq 4.1.0.
488       CZMQ_EXPORT void
489           zsock_set_xpub_nodrop (void *self, int xpub_nodrop);
490
491       //  Set socket option `router_mandatory`.
492       //  Available from libzmq 4.0.0.
493       CZMQ_EXPORT void
494           zsock_set_router_mandatory (void *self, int router_mandatory);
495
496       //  Set socket option `probe_router`.
497       //  Available from libzmq 4.0.0.
498       CZMQ_EXPORT void
499           zsock_set_probe_router (void *self, int probe_router);
500
501       //  Set socket option `req_relaxed`.
502       //  Available from libzmq 4.0.0.
503       CZMQ_EXPORT void
504           zsock_set_req_relaxed (void *self, int req_relaxed);
505
506       //  Set socket option `req_correlate`.
507       //  Available from libzmq 4.0.0.
508       CZMQ_EXPORT void
509           zsock_set_req_correlate (void *self, int req_correlate);
510
511       //  Set socket option `conflate`.
512       //  Available from libzmq 4.0.0.
513       CZMQ_EXPORT void
514           zsock_set_conflate (void *self, int conflate);
515
516       //  Get socket option `zap_domain`.
517       //  Available from libzmq 4.0.0.
518       //  Caller owns return value and must destroy it when done.
519       CZMQ_EXPORT char *
520           zsock_zap_domain (void *self);
521
522       //  Set socket option `zap_domain`.
523       //  Available from libzmq 4.0.0.
524       CZMQ_EXPORT void
525           zsock_set_zap_domain (void *self, const char *zap_domain);
526
527       //  Get socket option `mechanism`.
528       //  Available from libzmq 4.0.0.
529       //  Caller owns return value and must destroy it when done.
530       CZMQ_EXPORT int
531           zsock_mechanism (void *self);
532
533       //  Get socket option `plain_server`.
534       //  Available from libzmq 4.0.0.
535       //  Caller owns return value and must destroy it when done.
536       CZMQ_EXPORT int
537           zsock_plain_server (void *self);
538
539       //  Set socket option `plain_server`.
540       //  Available from libzmq 4.0.0.
541       CZMQ_EXPORT void
542           zsock_set_plain_server (void *self, int plain_server);
543
544       //  Get socket option `plain_username`.
545       //  Available from libzmq 4.0.0.
546       //  Caller owns return value and must destroy it when done.
547       CZMQ_EXPORT char *
548           zsock_plain_username (void *self);
549
550       //  Set socket option `plain_username`.
551       //  Available from libzmq 4.0.0.
552       CZMQ_EXPORT void
553           zsock_set_plain_username (void *self, const char *plain_username);
554
555       //  Get socket option `plain_password`.
556       //  Available from libzmq 4.0.0.
557       //  Caller owns return value and must destroy it when done.
558       CZMQ_EXPORT char *
559           zsock_plain_password (void *self);
560
561       //  Set socket option `plain_password`.
562       //  Available from libzmq 4.0.0.
563       CZMQ_EXPORT void
564           zsock_set_plain_password (void *self, const char *plain_password);
565
566       //  Get socket option `curve_server`.
567       //  Available from libzmq 4.0.0.
568       //  Caller owns return value and must destroy it when done.
569       CZMQ_EXPORT int
570           zsock_curve_server (void *self);
571
572       //  Set socket option `curve_server`.
573       //  Available from libzmq 4.0.0.
574       CZMQ_EXPORT void
575           zsock_set_curve_server (void *self, int curve_server);
576
577       //  Get socket option `curve_publickey`.
578       //  Available from libzmq 4.0.0.
579       //  Caller owns return value and must destroy it when done.
580       CZMQ_EXPORT char *
581           zsock_curve_publickey (void *self);
582
583       //  Set socket option `curve_publickey`.
584       //  Available from libzmq 4.0.0.
585       CZMQ_EXPORT void
586           zsock_set_curve_publickey (void *self, const char *curve_publickey);
587
588       //  Set socket option `curve_publickey` from 32-octet binary
589       //  Available from libzmq 4.0.0.
590       CZMQ_EXPORT void
591           zsock_set_curve_publickey_bin (void *self, const byte *curve_publickey);
592
593       //  Get socket option `curve_secretkey`.
594       //  Available from libzmq 4.0.0.
595       //  Caller owns return value and must destroy it when done.
596       CZMQ_EXPORT char *
597           zsock_curve_secretkey (void *self);
598
599       //  Set socket option `curve_secretkey`.
600       //  Available from libzmq 4.0.0.
601       CZMQ_EXPORT void
602           zsock_set_curve_secretkey (void *self, const char *curve_secretkey);
603
604       //  Set socket option `curve_secretkey` from 32-octet binary
605       //  Available from libzmq 4.0.0.
606       CZMQ_EXPORT void
607           zsock_set_curve_secretkey_bin (void *self, const byte *curve_secretkey);
608
609       //  Get socket option `curve_serverkey`.
610       //  Available from libzmq 4.0.0.
611       //  Caller owns return value and must destroy it when done.
612       CZMQ_EXPORT char *
613           zsock_curve_serverkey (void *self);
614
615       //  Set socket option `curve_serverkey`.
616       //  Available from libzmq 4.0.0.
617       CZMQ_EXPORT void
618           zsock_set_curve_serverkey (void *self, const char *curve_serverkey);
619
620       //  Set socket option `curve_serverkey` from 32-octet binary
621       //  Available from libzmq 4.0.0.
622       CZMQ_EXPORT void
623           zsock_set_curve_serverkey_bin (void *self, const byte *curve_serverkey);
624
625       //  Get socket option `gssapi_server`.
626       //  Available from libzmq 4.0.0.
627       //  Caller owns return value and must destroy it when done.
628       CZMQ_EXPORT int
629           zsock_gssapi_server (void *self);
630
631       //  Set socket option `gssapi_server`.
632       //  Available from libzmq 4.0.0.
633       CZMQ_EXPORT void
634           zsock_set_gssapi_server (void *self, int gssapi_server);
635
636       //  Get socket option `gssapi_plaintext`.
637       //  Available from libzmq 4.0.0.
638       //  Caller owns return value and must destroy it when done.
639       CZMQ_EXPORT int
640           zsock_gssapi_plaintext (void *self);
641
642       //  Set socket option `gssapi_plaintext`.
643       //  Available from libzmq 4.0.0.
644       CZMQ_EXPORT void
645           zsock_set_gssapi_plaintext (void *self, int gssapi_plaintext);
646
647       //  Get socket option `gssapi_principal`.
648       //  Available from libzmq 4.0.0.
649       //  Caller owns return value and must destroy it when done.
650       CZMQ_EXPORT char *
651           zsock_gssapi_principal (void *self);
652
653       //  Set socket option `gssapi_principal`.
654       //  Available from libzmq 4.0.0.
655       CZMQ_EXPORT void
656           zsock_set_gssapi_principal (void *self, const char *gssapi_principal);
657
658       //  Get socket option `gssapi_service_principal`.
659       //  Available from libzmq 4.0.0.
660       //  Caller owns return value and must destroy it when done.
661       CZMQ_EXPORT char *
662           zsock_gssapi_service_principal (void *self);
663
664       //  Set socket option `gssapi_service_principal`.
665       //  Available from libzmq 4.0.0.
666       CZMQ_EXPORT void
667           zsock_set_gssapi_service_principal (void *self, const char *gssapi_service_principal);
668
669       //  Get socket option `ipv6`.
670       //  Available from libzmq 4.0.0.
671       //  Caller owns return value and must destroy it when done.
672       CZMQ_EXPORT int
673           zsock_ipv6 (void *self);
674
675       //  Set socket option `ipv6`.
676       //  Available from libzmq 4.0.0.
677       CZMQ_EXPORT void
678           zsock_set_ipv6 (void *self, int ipv6);
679
680       //  Get socket option `immediate`.
681       //  Available from libzmq 4.0.0.
682       //  Caller owns return value and must destroy it when done.
683       CZMQ_EXPORT int
684           zsock_immediate (void *self);
685
686       //  Set socket option `immediate`.
687       //  Available from libzmq 4.0.0.
688       CZMQ_EXPORT void
689           zsock_set_immediate (void *self, int immediate);
690
691       //  Get socket option `type`.
692       //  Available from libzmq 3.0.0.
693       //  Caller owns return value and must destroy it when done.
694       CZMQ_EXPORT int
695           zsock_type (void *self);
696
697       //  Get socket option `sndhwm`.
698       //  Available from libzmq 3.0.0.
699       //  Caller owns return value and must destroy it when done.
700       CZMQ_EXPORT int
701           zsock_sndhwm (void *self);
702
703       //  Set socket option `sndhwm`.
704       //  Available from libzmq 3.0.0.
705       CZMQ_EXPORT void
706           zsock_set_sndhwm (void *self, int sndhwm);
707
708       //  Get socket option `rcvhwm`.
709       //  Available from libzmq 3.0.0.
710       //  Caller owns return value and must destroy it when done.
711       CZMQ_EXPORT int
712           zsock_rcvhwm (void *self);
713
714       //  Set socket option `rcvhwm`.
715       //  Available from libzmq 3.0.0.
716       CZMQ_EXPORT void
717           zsock_set_rcvhwm (void *self, int rcvhwm);
718
719       //  Get socket option `affinity`.
720       //  Available from libzmq 3.0.0.
721       //  Caller owns return value and must destroy it when done.
722       CZMQ_EXPORT int
723           zsock_affinity (void *self);
724
725       //  Set socket option `affinity`.
726       //  Available from libzmq 3.0.0.
727       CZMQ_EXPORT void
728           zsock_set_affinity (void *self, int affinity);
729
730       //  Set socket option `subscribe`.
731       //  Available from libzmq 3.0.0.
732       CZMQ_EXPORT void
733           zsock_set_subscribe (void *self, const char *subscribe);
734
735       //  Set socket option `unsubscribe`.
736       //  Available from libzmq 3.0.0.
737       CZMQ_EXPORT void
738           zsock_set_unsubscribe (void *self, const char *unsubscribe);
739
740       //  Get socket option `identity`.
741       //  Available from libzmq 3.0.0.
742       //  Caller owns return value and must destroy it when done.
743       CZMQ_EXPORT char *
744           zsock_identity (void *self);
745
746       //  Set socket option `identity`.
747       //  Available from libzmq 3.0.0.
748       CZMQ_EXPORT void
749           zsock_set_identity (void *self, const char *identity);
750
751       //  Get socket option `rate`.
752       //  Available from libzmq 3.0.0.
753       //  Caller owns return value and must destroy it when done.
754       CZMQ_EXPORT int
755           zsock_rate (void *self);
756
757       //  Set socket option `rate`.
758       //  Available from libzmq 3.0.0.
759       CZMQ_EXPORT void
760           zsock_set_rate (void *self, int rate);
761
762       //  Get socket option `recovery_ivl`.
763       //  Available from libzmq 3.0.0.
764       //  Caller owns return value and must destroy it when done.
765       CZMQ_EXPORT int
766           zsock_recovery_ivl (void *self);
767
768       //  Set socket option `recovery_ivl`.
769       //  Available from libzmq 3.0.0.
770       CZMQ_EXPORT void
771           zsock_set_recovery_ivl (void *self, int recovery_ivl);
772
773       //  Get socket option `sndbuf`.
774       //  Available from libzmq 3.0.0.
775       //  Caller owns return value and must destroy it when done.
776       CZMQ_EXPORT int
777           zsock_sndbuf (void *self);
778
779       //  Set socket option `sndbuf`.
780       //  Available from libzmq 3.0.0.
781       CZMQ_EXPORT void
782           zsock_set_sndbuf (void *self, int sndbuf);
783
784       //  Get socket option `rcvbuf`.
785       //  Available from libzmq 3.0.0.
786       //  Caller owns return value and must destroy it when done.
787       CZMQ_EXPORT int
788           zsock_rcvbuf (void *self);
789
790       //  Set socket option `rcvbuf`.
791       //  Available from libzmq 3.0.0.
792       CZMQ_EXPORT void
793           zsock_set_rcvbuf (void *self, int rcvbuf);
794
795       //  Get socket option `linger`.
796       //  Available from libzmq 3.0.0.
797       //  Caller owns return value and must destroy it when done.
798       CZMQ_EXPORT int
799           zsock_linger (void *self);
800
801       //  Set socket option `linger`.
802       //  Available from libzmq 3.0.0.
803       CZMQ_EXPORT void
804           zsock_set_linger (void *self, int linger);
805
806       //  Get socket option `reconnect_ivl`.
807       //  Available from libzmq 3.0.0.
808       //  Caller owns return value and must destroy it when done.
809       CZMQ_EXPORT int
810           zsock_reconnect_ivl (void *self);
811
812       //  Set socket option `reconnect_ivl`.
813       //  Available from libzmq 3.0.0.
814       CZMQ_EXPORT void
815           zsock_set_reconnect_ivl (void *self, int reconnect_ivl);
816
817       //  Get socket option `reconnect_ivl_max`.
818       //  Available from libzmq 3.0.0.
819       //  Caller owns return value and must destroy it when done.
820       CZMQ_EXPORT int
821           zsock_reconnect_ivl_max (void *self);
822
823       //  Set socket option `reconnect_ivl_max`.
824       //  Available from libzmq 3.0.0.
825       CZMQ_EXPORT void
826           zsock_set_reconnect_ivl_max (void *self, int reconnect_ivl_max);
827
828       //  Get socket option `backlog`.
829       //  Available from libzmq 3.0.0.
830       //  Caller owns return value and must destroy it when done.
831       CZMQ_EXPORT int
832           zsock_backlog (void *self);
833
834       //  Set socket option `backlog`.
835       //  Available from libzmq 3.0.0.
836       CZMQ_EXPORT void
837           zsock_set_backlog (void *self, int backlog);
838
839       //  Get socket option `maxmsgsize`.
840       //  Available from libzmq 3.0.0.
841       //  Caller owns return value and must destroy it when done.
842       CZMQ_EXPORT int
843           zsock_maxmsgsize (void *self);
844
845       //  Set socket option `maxmsgsize`.
846       //  Available from libzmq 3.0.0.
847       CZMQ_EXPORT void
848           zsock_set_maxmsgsize (void *self, int maxmsgsize);
849
850       //  Get socket option `multicast_hops`.
851       //  Available from libzmq 3.0.0.
852       //  Caller owns return value and must destroy it when done.
853       CZMQ_EXPORT int
854           zsock_multicast_hops (void *self);
855
856       //  Set socket option `multicast_hops`.
857       //  Available from libzmq 3.0.0.
858       CZMQ_EXPORT void
859           zsock_set_multicast_hops (void *self, int multicast_hops);
860
861       //  Get socket option `rcvtimeo`.
862       //  Available from libzmq 3.0.0.
863       //  Caller owns return value and must destroy it when done.
864       CZMQ_EXPORT int
865           zsock_rcvtimeo (void *self);
866
867       //  Set socket option `rcvtimeo`.
868       //  Available from libzmq 3.0.0.
869       CZMQ_EXPORT void
870           zsock_set_rcvtimeo (void *self, int rcvtimeo);
871
872       //  Get socket option `sndtimeo`.
873       //  Available from libzmq 3.0.0.
874       //  Caller owns return value and must destroy it when done.
875       CZMQ_EXPORT int
876           zsock_sndtimeo (void *self);
877
878       //  Set socket option `sndtimeo`.
879       //  Available from libzmq 3.0.0.
880       CZMQ_EXPORT void
881           zsock_set_sndtimeo (void *self, int sndtimeo);
882
883       //  Set socket option `xpub_verbose`.
884       //  Available from libzmq 3.0.0.
885       CZMQ_EXPORT void
886           zsock_set_xpub_verbose (void *self, int xpub_verbose);
887
888       //  Get socket option `tcp_keepalive`.
889       //  Available from libzmq 3.0.0.
890       //  Caller owns return value and must destroy it when done.
891       CZMQ_EXPORT int
892           zsock_tcp_keepalive (void *self);
893
894       //  Set socket option `tcp_keepalive`.
895       //  Available from libzmq 3.0.0.
896       CZMQ_EXPORT void
897           zsock_set_tcp_keepalive (void *self, int tcp_keepalive);
898
899       //  Get socket option `tcp_keepalive_idle`.
900       //  Available from libzmq 3.0.0.
901       //  Caller owns return value and must destroy it when done.
902       CZMQ_EXPORT int
903           zsock_tcp_keepalive_idle (void *self);
904
905       //  Set socket option `tcp_keepalive_idle`.
906       //  Available from libzmq 3.0.0.
907       CZMQ_EXPORT void
908           zsock_set_tcp_keepalive_idle (void *self, int tcp_keepalive_idle);
909
910       //  Get socket option `tcp_keepalive_cnt`.
911       //  Available from libzmq 3.0.0.
912       //  Caller owns return value and must destroy it when done.
913       CZMQ_EXPORT int
914           zsock_tcp_keepalive_cnt (void *self);
915
916       //  Set socket option `tcp_keepalive_cnt`.
917       //  Available from libzmq 3.0.0.
918       CZMQ_EXPORT void
919           zsock_set_tcp_keepalive_cnt (void *self, int tcp_keepalive_cnt);
920
921       //  Get socket option `tcp_keepalive_intvl`.
922       //  Available from libzmq 3.0.0.
923       //  Caller owns return value and must destroy it when done.
924       CZMQ_EXPORT int
925           zsock_tcp_keepalive_intvl (void *self);
926
927       //  Set socket option `tcp_keepalive_intvl`.
928       //  Available from libzmq 3.0.0.
929       CZMQ_EXPORT void
930           zsock_set_tcp_keepalive_intvl (void *self, int tcp_keepalive_intvl);
931
932       //  Get socket option `tcp_accept_filter`.
933       //  Available from libzmq 3.0.0.
934       //  Caller owns return value and must destroy it when done.
935       CZMQ_EXPORT char *
936           zsock_tcp_accept_filter (void *self);
937
938       //  Set socket option `tcp_accept_filter`.
939       //  Available from libzmq 3.0.0.
940       CZMQ_EXPORT void
941           zsock_set_tcp_accept_filter (void *self, const char *tcp_accept_filter);
942
943       //  Get socket option `rcvmore`.
944       //  Available from libzmq 3.0.0.
945       //  Caller owns return value and must destroy it when done.
946       CZMQ_EXPORT int
947           zsock_rcvmore (void *self);
948
949       //  Get socket option `fd`.
950       //  Available from libzmq 3.0.0.
951       //  Caller owns return value and must destroy it when done.
952       CZMQ_EXPORT SOCKET
953           zsock_fd (void *self);
954
955       //  Get socket option `events`.
956       //  Available from libzmq 3.0.0.
957       //  Caller owns return value and must destroy it when done.
958       CZMQ_EXPORT int
959           zsock_events (void *self);
960
961       //  Get socket option `last_endpoint`.
962       //  Available from libzmq 3.0.0.
963       //  Caller owns return value and must destroy it when done.
964       CZMQ_EXPORT char *
965           zsock_last_endpoint (void *self);
966
967       //  Set socket option `router_raw`.
968       //  Available from libzmq 3.0.0.
969       CZMQ_EXPORT void
970           zsock_set_router_raw (void *self, int router_raw);
971
972       //  Get socket option `ipv4only`.
973       //  Available from libzmq 3.0.0.
974       //  Caller owns return value and must destroy it when done.
975       CZMQ_EXPORT int
976           zsock_ipv4only (void *self);
977
978       //  Set socket option `ipv4only`.
979       //  Available from libzmq 3.0.0.
980       CZMQ_EXPORT void
981           zsock_set_ipv4only (void *self, int ipv4only);
982
983       //  Set socket option `delay_attach_on_connect`.
984       //  Available from libzmq 3.0.0.
985       CZMQ_EXPORT void
986           zsock_set_delay_attach_on_connect (void *self, int delay_attach_on_connect);
987
988       //  Self test of this class.
989       CZMQ_EXPORT void
990           zsock_test (bool verbose);
991
992       #ifdef CZMQ_BUILD_DRAFT_API
993       //  *** Draft method, for development use, may change without warning ***
994       //  Create a SERVER socket. Default action is bind.
995       CZMQ_EXPORT zsock_t *
996           zsock_new_server (const char *endpoint);
997
998       //  *** Draft method, for development use, may change without warning ***
999       //  Create a CLIENT socket. Default action is connect.
1000       CZMQ_EXPORT zsock_t *
1001           zsock_new_client (const char *endpoint);
1002
1003       //  *** Draft method, for development use, may change without warning ***
1004       //  Create a RADIO socket. Default action is bind.
1005       CZMQ_EXPORT zsock_t *
1006           zsock_new_radio (const char *endpoint);
1007
1008       //  *** Draft method, for development use, may change without warning ***
1009       //  Create a DISH socket. Default action is connect.
1010       CZMQ_EXPORT zsock_t *
1011           zsock_new_dish (const char *endpoint);
1012
1013       //  *** Draft method, for development use, may change without warning ***
1014       //  Create a GATHER socket. Default action is bind.
1015       CZMQ_EXPORT zsock_t *
1016           zsock_new_gather (const char *endpoint);
1017
1018       //  *** Draft method, for development use, may change without warning ***
1019       //  Create a SCATTER socket. Default action is connect.
1020       CZMQ_EXPORT zsock_t *
1021           zsock_new_scatter (const char *endpoint);
1022
1023       //  *** Draft method, for development use, may change without warning ***
1024       //  Return socket routing ID if any. This returns 0 if the socket is not
1025       //  of type ZMQ_SERVER or if no request was already received on it.
1026       CZMQ_EXPORT uint32_t
1027           zsock_routing_id (zsock_t *self);
1028
1029       //  *** Draft method, for development use, may change without warning ***
1030       //  Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
1031       //  This will be used when sending messages on the socket via the zsock API.
1032       CZMQ_EXPORT void
1033           zsock_set_routing_id (zsock_t *self, uint32_t routing_id);
1034
1035       //  *** Draft method, for development use, may change without warning ***
1036       //  Join a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
1037       //  Returns 0 if OK, -1 if failed.
1038       CZMQ_EXPORT int
1039           zsock_join (void *self, const char *group);
1040
1041       //  *** Draft method, for development use, may change without warning ***
1042       //  Leave a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
1043       //  Returns 0 if OK, -1 if failed.
1044       CZMQ_EXPORT int
1045           zsock_leave (void *self, const char *group);
1046
1047       #endif // CZMQ_BUILD_DRAFT_API
1048       Please add '@interface' section in './../src/zsock.c'.
1049

DESCRIPTION

1051       The zsock class wraps the libzmq socket handle (a void *) with a proper
1052       structure that follows the CLASS rules for construction and
1053       destruction. Some zsock methods take a void * "polymorphic" reference,
1054       which can be either a zsock_t or a zactor_t reference, or a libzmq void
1055       *.
1056
1057       Please add @discuss section in ./../src/zsock.c.
1058

EXAMPLE

1060       From zsock_test method.
1061
1062           zsock_t *writer = zsock_new_push ("@tcp://127.0.0.1:5560");
1063           assert (writer);
1064           assert (zsock_resolve (writer) != writer);
1065           assert (streq (zsock_type_str (writer), "PUSH"));
1066
1067           int rc;
1068           #if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (3, 2, 0))
1069           //  Check unbind
1070           rc = zsock_unbind (writer, "tcp://127.0.0.1:%d", 5560);
1071           assert (rc == 0);
1072
1073           //  In some cases and especially when running under Valgrind, doing
1074           //  a bind immediately after an unbind causes an EADDRINUSE error.
1075           //  Even a short sleep allows the OS to release the port for reuse.
1076           zclock_sleep (100);
1077
1078           //  Bind again
1079           rc = zsock_bind (writer, "tcp://127.0.0.1:%d", 5560);
1080           assert (rc == 5560);
1081           assert (streq (zsock_endpoint (writer), "tcp://127.0.0.1:5560"));
1082           #endif
1083
1084           zsock_t *reader = zsock_new_pull (">tcp://127.0.0.1:5560");
1085           assert (reader);
1086           assert (zsock_resolve (reader) != reader);
1087           assert (streq (zsock_type_str (reader), "PULL"));
1088
1089           //  Basic Hello, World
1090           zstr_send (writer, "Hello, World");
1091           zmsg_t *msg = zmsg_recv (reader);
1092           assert (msg);
1093           char *string = zmsg_popstr (msg);
1094           assert (streq (string, "Hello, World"));
1095           free (string);
1096           zmsg_destroy (&msg);
1097
1098           //  Test resolve libzmq socket
1099           #if (ZMQ_VERSION >= ZMQ_MAKE_VERSION (3, 2, 0))
1100           void *zmq_ctx = zmq_ctx_new ();
1101           #else
1102           void *zmq_ctx = zmq_ctx_new (1);
1103           #endif
1104           assert (zmq_ctx);
1105           void *zmq_sock = zmq_socket (zmq_ctx, ZMQ_PUB);
1106           assert (zmq_sock);
1107           assert (zsock_resolve (zmq_sock) == zmq_sock);
1108           zmq_close (zmq_sock);
1109           zmq_ctx_term (zmq_ctx);
1110
1111           //  Test resolve zsock
1112           zsock_t *resolve = zsock_new_pub("@tcp://127.0.0.1:5561");
1113           assert (resolve);
1114           assert (zsock_resolve (resolve) == resolve->handle);
1115           zsock_destroy (&resolve);
1116
1117           //  Test resolve FD
1118           SOCKET fd = zsock_fd (reader);
1119           assert (zsock_resolve ((void *) &fd) == NULL);
1120
1121           //  Test binding to ephemeral ports, sequential and random
1122           int port = zsock_bind (writer, "tcp://127.0.0.1:*");
1123           assert (port >= DYNAMIC_FIRST && port <= DYNAMIC_LAST);
1124           port = zsock_bind (writer, "tcp://127.0.0.1:*[50000-]");
1125           assert (port >= 50000 && port <= DYNAMIC_LAST);
1126           port = zsock_bind (writer, "tcp://127.0.0.1:*[-50001]");
1127           assert (port >= DYNAMIC_FIRST && port <= 50001);
1128           port = zsock_bind (writer, "tcp://127.0.0.1:*[60000-60050]");
1129           assert (port >= 60000 && port <= 60050);
1130
1131           port = zsock_bind (writer, "tcp://127.0.0.1:!");
1132           assert (port >= DYNAMIC_FIRST && port <= DYNAMIC_LAST);
1133           port = zsock_bind (writer, "tcp://127.0.0.1:![50000-]");
1134           assert (port >= 50000 && port <= DYNAMIC_LAST);
1135           port = zsock_bind (writer, "tcp://127.0.0.1:![-50001]");
1136           assert (port >= DYNAMIC_FIRST && port <= 50001);
1137           port = zsock_bind (writer, "tcp://127.0.0.1:![60000-60050]");
1138           assert (port >= 60000 && port <= 60050);
1139
1140           //  Test zsock_attach method
1141           zsock_t *server = zsock_new (ZMQ_DEALER);
1142           assert (server);
1143           rc = zsock_attach (server, "@inproc://myendpoint,tcp://127.0.0.1:5556,inproc://others", true);
1144           assert (rc == 0);
1145           rc = zsock_attach (server, "", false);
1146           assert (rc == 0);
1147           rc = zsock_attach (server, NULL, true);
1148           assert (rc == 0);
1149           rc = zsock_attach (server, ">a,@b, c,, ", false);
1150           assert (rc == -1);
1151           zsock_destroy (&server);
1152
1153           //  Test zsock_endpoint method
1154           rc = zsock_bind (writer, "inproc://test.%s", "writer");
1155           assert (rc == 0);
1156           assert (streq (zsock_endpoint (writer), "inproc://test.writer"));
1157
1158           //  Test error state when connecting to an invalid socket type
1159           //  ('txp://' instead of 'tcp://', typo intentional)
1160           rc = zsock_connect (reader, "txp://127.0.0.1:5560");
1161           assert (rc == -1);
1162
1163           //  Test signal/wait methods
1164           rc = zsock_signal (writer, 123);
1165           assert (rc == 0);
1166           rc = zsock_wait (reader);
1167           assert (rc == 123);
1168
1169           //  Test zsock_send/recv pictures
1170           uint8_t  number1 = 123;
1171           uint16_t number2 = 123 * 123;
1172           uint32_t number4 = 123 * 123;
1173           number4 *= 123;
1174           uint32_t number4_MAX = UINT32_MAX;
1175           uint64_t number8 = 123 * 123;
1176           number8 *= 123;
1177           number8 *= 123;
1178           uint64_t number8_MAX = UINT64_MAX;
1179
1180           zchunk_t *chunk = zchunk_new ("HELLO", 5);
1181           assert (chunk);
1182           zframe_t *frame = zframe_new ("WORLD", 5);
1183           assert (frame);
1184           zhashx_t *hash = zhashx_new ();
1185           assert (hash);
1186           zuuid_t *uuid = zuuid_new ();
1187           assert (uuid);
1188           zhashx_set_destructor (hash, (zhashx_destructor_fn *) zstr_free);
1189           zhashx_set_duplicator (hash, (zhashx_duplicator_fn *) strdup);
1190           zhashx_insert (hash, "1", "value A");
1191           zhashx_insert (hash, "2", "value B");
1192           char *original = "pointer";
1193
1194           //  Test zsock_recv into each supported type
1195           zsock_send (writer, "i124488zsbcfUhp",
1196                       -12345, number1, number2, number4, number4_MAX,
1197                       number8, number8_MAX,
1198                       "This is a string", "ABCDE", 5,
1199                       chunk, frame, uuid, hash, original);
1200           char *uuid_str = strdup (zuuid_str (uuid));
1201           zchunk_destroy (&chunk);
1202           zframe_destroy (&frame);
1203           zuuid_destroy (&uuid);
1204           zhashx_destroy (&hash);
1205
1206           int integer;
1207           byte *data;
1208           size_t size;
1209           char *pointer;
1210           number8_MAX = number8 = number4_MAX = number4 = number2 = number1 = 0ULL;
1211           rc = zsock_recv (reader, "i124488zsbcfUhp",
1212                            &integer, &number1, &number2, &number4, &number4_MAX,
1213                            &number8, &number8_MAX, &string, &data, &size, &chunk,
1214                            &frame, &uuid, &hash, &pointer);
1215           assert (rc == 0);
1216           assert (integer == -12345);
1217           assert (number1 == 123);
1218           assert (number2 == 123 * 123);
1219           assert (number4 == 123 * 123 * 123);
1220           assert (number4_MAX == UINT32_MAX);
1221           assert (number8 == 123 * 123 * 123 * 123);
1222           assert (number8_MAX == UINT64_MAX);
1223           assert (streq (string, "This is a string"));
1224           assert (memcmp (data, "ABCDE", 5) == 0);
1225           assert (size == 5);
1226           assert (memcmp (zchunk_data (chunk), "HELLO", 5) == 0);
1227           assert (zchunk_size (chunk) == 5);
1228           assert (streq (uuid_str, zuuid_str (uuid)));
1229           assert (memcmp (zframe_data (frame), "WORLD", 5) == 0);
1230           assert (zframe_size (frame) == 5);
1231           char *value = (char *) zhashx_lookup (hash, "1");
1232           assert (streq (value, "value A"));
1233           value = (char *) zhashx_lookup (hash, "2");
1234           assert (streq (value, "value B"));
1235           assert (original == pointer);
1236           free (string);
1237           free (data);
1238           free (uuid_str);
1239           zframe_destroy (&frame);
1240           zchunk_destroy (&chunk);
1241           zhashx_destroy (&hash);
1242           zuuid_destroy (&uuid);
1243
1244           //  Test zsock_recv of short message; this lets us return a failure
1245           //  with a status code and then nothing else; the receiver will get
1246           //  the status code and NULL/zero for all other values
1247           zsock_send (writer, "i", -1);
1248           zsock_recv (reader, "izsbcfp",
1249               &integer, &string, &data, &size, &chunk, &frame, &pointer);
1250           assert (integer == -1);
1251           assert (string == NULL);
1252           assert (data == NULL);
1253           assert (size == 0);
1254           assert (chunk == NULL);
1255           assert (frame == NULL);
1256           assert (pointer == NULL);
1257
1258           msg = zmsg_new ();
1259           zmsg_addstr (msg, "frame 1");
1260           zmsg_addstr (msg, "frame 2");
1261           zsock_send (writer, "szm", "header", msg);
1262           zmsg_destroy (&msg);
1263
1264           zsock_recv (reader, "szm", &string, &msg);
1265
1266           assert (streq ("header", string));
1267           assert (zmsg_size (msg) == 2);
1268           assert (zframe_streq (zmsg_first (msg), "frame 1"));
1269           assert (zframe_streq (zmsg_next (msg), "frame 2"));
1270           zstr_free (&string);
1271           zmsg_destroy (&msg);
1272
1273           //  Test zsock_recv with null arguments
1274           chunk = zchunk_new ("HELLO", 5);
1275           assert (chunk);
1276           frame = zframe_new ("WORLD", 5);
1277           assert (frame);
1278           zsock_send (writer, "izsbcfp",
1279                       -12345, "This is a string", "ABCDE", 5, chunk, frame, original);
1280           zframe_destroy (&frame);
1281           zchunk_destroy (&chunk);
1282           zsock_recv (reader, "izsbcfp", &integer, NULL, NULL, NULL, &chunk, NULL, NULL);
1283           assert (integer == -12345);
1284           assert (memcmp (zchunk_data (chunk), "HELLO", 5) == 0);
1285           assert (zchunk_size (chunk) == 5);
1286           zchunk_destroy (&chunk);
1287
1288           //  Test zsock_bsend/brecv pictures with binary encoding
1289           frame = zframe_new ("Hello", 5);
1290           chunk = zchunk_new ("World", 5);
1291
1292           msg = zmsg_new ();
1293           zmsg_addstr (msg, "Hello");
1294           zmsg_addstr (msg, "World");
1295
1296           zsock_bsend (writer, "1248sSpcfm",
1297                        number1, number2, number4, number8,
1298                        "Hello, World",
1299                        "Goodbye cruel World!",
1300                        original,
1301                        chunk, frame, msg);
1302           zchunk_destroy (&chunk);
1303           zframe_destroy (&frame);
1304           zmsg_destroy (&msg);
1305
1306           number8 = number4 = number2 = number1 = 0;
1307           char *longstr;
1308           zsock_brecv (reader, "1248sSpcfm",
1309                        &number1, &number2, &number4, &number8,
1310                        &string, &longstr,
1311                        &pointer,
1312                        &chunk, &frame, &msg);
1313           assert (number1 == 123);
1314           assert (number2 == 123 * 123);
1315           assert (number4 == 123 * 123 * 123);
1316           assert (number8 == 123 * 123 * 123 * 123);
1317           assert (streq (string, "Hello, World"));
1318           assert (streq (longstr, "Goodbye cruel World!"));
1319           assert (pointer == original);
1320           zstr_free (&longstr);
1321           zchunk_destroy (&chunk);
1322           zframe_destroy (&frame);
1323           zmsg_destroy (&msg);
1324
1325           #ifdef ZMQ_SERVER
1326
1327           //  Test zsock_bsend/brecv pictures with binary encoding on SERVER and CLIENT sockets
1328           server = zsock_new_server ("tcp://127.0.0.1:5561");
1329           assert (server);
1330           zsock_t* client = zsock_new_client ("tcp://127.0.0.1:5561");
1331           assert (client);
1332
1333           //  From client to server
1334           chunk = zchunk_new ("World", 5);
1335           zsock_bsend (client, "1248sSpc",
1336                        number1, number2, number4, number8,
1337                        "Hello, World",
1338                        "Goodbye cruel World!",
1339                        original,
1340                        chunk);
1341           zchunk_destroy (&chunk);
1342
1343           number8 = number4 = number2 = number1 = 0;
1344           zsock_brecv (server, "1248sSpc",
1345                        &number1, &number2, &number4, &number8,
1346                        &string, &longstr,
1347                        &pointer,
1348                        &chunk);
1349           assert (number1 == 123);
1350           assert (number2 == 123 * 123);
1351           assert (number4 == 123 * 123 * 123);
1352           assert (number8 == 123 * 123 * 123 * 123);
1353           assert (streq (string, "Hello, World"));
1354           assert (streq (longstr, "Goodbye cruel World!"));
1355           assert (pointer == original);
1356           assert (zsock_routing_id (server));
1357           zstr_free (&longstr);
1358           zchunk_destroy (&chunk);
1359
1360           //  From server to client
1361           chunk = zchunk_new ("World", 5);
1362           zsock_bsend (server, "1248sSpc",
1363                        number1, number2, number4, number8,
1364                        "Hello, World",
1365                        "Goodbye cruel World!",
1366                        original,
1367                        chunk);
1368           zchunk_destroy (&chunk);
1369
1370           number8 = number4 = number2 = number1 = 0;
1371           zsock_brecv (client, "1248sSpc",
1372                        &number1, &number2, &number4, &number8,
1373                        &string, &longstr,
1374                        &pointer,
1375                        &chunk);
1376           assert (number1 == 123);
1377           assert (number2 == 123 * 123);
1378           assert (number4 == 123 * 123 * 123);
1379           assert (number8 == 123 * 123 * 123 * 123);
1380           assert (streq (string, "Hello, World"));
1381           assert (streq (longstr, "Goodbye cruel World!"));
1382           assert (pointer == original);
1383           assert (zsock_routing_id (client) == 0);
1384           zstr_free (&longstr);
1385           zchunk_destroy (&chunk);
1386
1387           zsock_destroy (&client);
1388           zsock_destroy (&server);
1389
1390           #endif
1391
1392           #ifdef ZMQ_SCATTER
1393
1394           zsock_t* gather = zsock_new_gather ("inproc://test-gather-scatter");
1395           assert (gather);
1396           zsock_t* scatter = zsock_new_scatter ("inproc://test-gather-scatter");
1397           assert (scatter);
1398
1399           rc = zstr_send (scatter, "HELLO");
1400           assert (rc == 0);
1401
1402           char* message;
1403           message = zstr_recv (gather);
1404           assert (streq(message, "HELLO"));
1405           zstr_free (&message);
1406
1407           zsock_destroy (&gather);
1408           zsock_destroy (&scatter);
1409
1410           #endif
1411
1412           //  Check that we can send a zproto format message
1413           zsock_bsend (writer, "1111sS4", 0xAA, 0xA0, 0x02, 0x01, "key", "value", 1234);
1414           zgossip_msg_t *gossip = zgossip_msg_new ();
1415           zgossip_msg_recv (gossip, reader);
1416           assert (zgossip_msg_id (gossip) == ZGOSSIP_MSG_PUBLISH);
1417           zgossip_msg_destroy (&gossip);
1418
1419           zsock_destroy (&reader);
1420           zsock_destroy (&writer);
1421
1422

AUTHORS

1424       The czmq manual was written by the authors in the AUTHORS file.
1425

RESOURCES

1427       Main web site:
1428
1429       Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>
1430
1432       Copyright (c) the Contributors as noted in the AUTHORS file. This file
1433       is part of CZMQ, the high-level C binding for 0MQ:
1434       http://czmq.zeromq.org. This Source Code Form is subject to the terms
1435       of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
1436       distributed with this file, You can obtain one at
1437       http://mozilla.org/MPL/2.0/. LICENSE included with the czmq
1438       distribution.
1439

NOTES

1441        1. zeromq-dev@lists.zeromq.org
1442           mailto:zeromq-dev@lists.zeromq.org
1443
1444
1445
1446CZMQ 4.0.2                        12/31/2016                          ZSOCK(3)
Impressum