1 /*
2     Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4     This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6     libzmq is free software; you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 3 of the License, or
9     (at your option) any later version.
10 
11     As a special exception, the Contributors give you permission to link
12     this library with independent modules to produce an executable,
13     regardless of the license terms of these independent modules, and to
14     copy and distribute the resulting executable under terms of your choice,
15     provided that you also meet, for each linked independent module, the
16     terms and conditions of the license of that module. An independent
17     module is a module which is not derived from or based on this library.
18     If you modify this library, you must extend this exception to your
19     version of the library.
20 
21     libzmq is distributed in the hope that it will be useful, but WITHOUT
22     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
24     License for more details.
25 
26     You should have received a copy of the GNU Lesser General Public License
27     along with this program.  If not, see <http://www.gnu.org/licenses/>.
28 
29     *************************************************************************
30     NOTE to contributors. This file comprises the principal public contract
31     for ZeroMQ API users. Any change to this file supplied in a stable
32     release SHOULD not break existing applications.
33     In practice this means that the value of constants must not change, and
34     that old values may not be reused for new constants.
35     *************************************************************************
36 */
37 module deimos.zmq.zmq;
38 
39 import core.stdc.config;
40 
41 nothrow extern (C)
42 {
43 
44 /*  Version macros for compile-time API version detection                     */
45 enum ZMQ_VERSION_MAJOR = 4;
46 enum ZMQ_VERSION_MINOR = 3;
47 enum ZMQ_VERSION_PATCH = 2;
48 
49 int ZMQ_MAKE_VERSION(int major, int minor, int patch)
50 {
51     return major * 10000 + minor * 100 + patch;
52 }
53 enum ZMQ_VERSION =
54     ZMQ_MAKE_VERSION(ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH);
55 
56 /******************************************************************************/
57 /*  0MQ errors.                                                               */
58 /******************************************************************************/
59 
60 /*  A number random anough not to collide with different errno ranges on      */
61 /*  different OSes. The assumption is that error_t is at least 32-bit type.   */
62 enum
63 {
64     ZMQ_HAUSNUMERO = 156384712,
65 
66 /*  On Windows platform some of the standard POSIX errnos are not defined.    */
67     ENOTSUP         = (ZMQ_HAUSNUMERO + 1),
68     EPROTONOSUPPORT = (ZMQ_HAUSNUMERO + 2),
69     ENOBUFS         = (ZMQ_HAUSNUMERO + 3),
70     ENETDOWN        = (ZMQ_HAUSNUMERO + 4),
71     EADDRINUSE      = (ZMQ_HAUSNUMERO + 5),
72     EADDRNOTAVAIL   = (ZMQ_HAUSNUMERO + 6),
73     ECONNREFUSED    = (ZMQ_HAUSNUMERO + 7),
74     EINPROGRESS     = (ZMQ_HAUSNUMERO + 8),
75     ENOTSOCK        = (ZMQ_HAUSNUMERO + 9),
76     EMSGSIZE        = (ZMQ_HAUSNUMERO + 10),
77     EAFNOSUPPORT    = (ZMQ_HAUSNUMERO + 11),
78     ENETUNREACH     = (ZMQ_HAUSNUMERO + 12),
79     ECONNABORTED    = (ZMQ_HAUSNUMERO + 13),
80     ECONNRESET      = (ZMQ_HAUSNUMERO + 14),
81     ENOTCONN        = (ZMQ_HAUSNUMERO + 15),
82     ETIMEDOUT       = (ZMQ_HAUSNUMERO + 16),
83     EHOSTUNREACH    = (ZMQ_HAUSNUMERO + 17),
84     ENETRESET       = (ZMQ_HAUSNUMERO + 18),
85 
86 /*  Native 0MQ error codes.                                                   */
87     EFSM            = (ZMQ_HAUSNUMERO + 51),
88     ENOCOMPATPROTO  = (ZMQ_HAUSNUMERO + 52),
89     ETERM           = (ZMQ_HAUSNUMERO + 53),
90     EMTHREAD        = (ZMQ_HAUSNUMERO + 54)
91 }//enum error_code
92 
93 /*  This function retrieves the errno as it is known to 0MQ library. The goal */
94 /*  of this function is to make the code 100% portable, including where 0MQ   */
95 /*  compiled with certain CRT library (on Windows) is linked to an            */
96 /*  application that uses different CRT library.                              */
97 int zmq_errno();
98 
99 /*  Resolves system errors and 0MQ errors to human-readable string.           */
100 const(char)* zmq_strerror(int errnum_);
101 
102 /*  Run-time API version detection                                            */
103 void zmq_version (int* major_, int* minor_, int* patch_);
104 
105 /******************************************************************************/
106 /*  0MQ infrastructure (a.k.a. context) initialisation & termination.         */
107 /******************************************************************************/
108 
109 /*  Context options                                                           */
110 enum ZMQ_IO_THREADS = 1;
111 enum ZMQ_MAX_SOCKETS = 2;
112 enum ZMQ_SOCKET_LIMIT = 3;
113 enum ZMQ_THREAD_PRIORITY = 3;
114 enum ZMQ_THREAD_SCHED_POLICY = 4;
115 enum ZMQ_MAX_MSGSZ = 5;
116 enum ZMQ_MSG_T_SIZE = 6;
117 enum ZMQ_THREAD_AFFINITY_CPU_ADD = 7;
118 enum ZMQ_THREAD_AFFINITY_CPU_REMOVE = 8;
119 enum ZMQ_THREAD_NAME_PREFIX = 9;
120 
121 /*  Default for new contexts                                                  */
122 enum
123 {
124     ZMQ_IO_THREADS_DFLT = 1,
125     ZMQ_MAX_SOCKETS_DFLT = 1023,
126     ZMQ_THREAD_PRIORITY_DFLT = -1,
127     ZMQ_THREAD_SCHED_POLICY_DFLT = -1,
128 }
129 
130 void* zmq_ctx_new();
131 int zmq_ctx_term(void* context_);
132 int zmq_ctx_shutdown(void* context_);
133 int zmq_ctx_set(void* context_, int option_, int optval_);
134 int zmq_ctx_get(void* context_, int option_);
135 
136 /*  Old (legacy) API                                                          */
137 void* zmq_init(int io_threads_);
138 int zmq_term(void* context_);
139 int zmq_ctx_destroy(void* context_);
140 
141 
142 /******************************************************************************/
143 /*  0MQ message definition.                                                   */
144 /******************************************************************************/
145 
146 /* Some architectures, like sparc64 and some variance of aarch64, enforce pointer
147  * alignment and raise sigbus on violations. Make sure applications allocate
148  * zmq_msg_t on addresses aligned on a pointer-size-boundary to avoid this issue.
149  */
150 struct zmq_msg_t
151 {
152     align((void*).sizeof) ubyte[64] _;
153 }
154 
155 int zmq_msg_init(zmq_msg_t* msg_);
156 int zmq_msg_init_size(zmq_msg_t* msg_, size_t size_);
157 int zmq_msg_init_data(
158     zmq_msg_t* msg_, void* data_, size_t size_, void function(void* data_, void* hint_) nothrow ffn_, void* hint_);
159 int zmq_msg_send(zmq_msg_t* msg_, void* s_, int flags_);
160 int zmq_msg_recv(zmq_msg_t* msg_, void* s_, int flags_);
161 int zmq_msg_close(zmq_msg_t* msg_);
162 int zmq_msg_move(zmq_msg_t* dest_, zmq_msg_t* src_);
163 int zmq_msg_copy(zmq_msg_t* dest_, zmq_msg_t* src_);
164 void* zmq_msg_data(zmq_msg_t* msg_);
165 size_t zmq_msg_size(const(zmq_msg_t)* msg_);
166 int zmq_msg_more(const(zmq_msg_t)* msg_);
167 int zmq_msg_get(const(zmq_msg_t)* msg_, int property_);
168 int zmq_msg_set(zmq_msg_t* msg_, int property_, int optval_);
169 const(char)* zmq_msg_gets(const(zmq_msg_t)* msg_,
170                           const(char)* property_);
171 
172 /******************************************************************************/
173 /*  0MQ socket definition.                                                    */
174 /******************************************************************************/
175 
176 /*  Socket types.                                                             */
177 enum
178 {
179     ZMQ_PAIR        = 0,
180     ZMQ_PUB         = 1,
181     ZMQ_SUB         = 2,
182     ZMQ_REQ         = 3,
183     ZMQ_REP         = 4,
184     ZMQ_DEALER      = 5,
185     ZMQ_ROUTER      = 6,
186     ZMQ_PULL        = 7,
187     ZMQ_PUSH        = 8,
188     ZMQ_XPUB        = 9,
189     ZMQ_XSUB        = 10,
190     ZMQ_STREAM      = 11,
191 }
192 
193 /*  Deprecated aliases                                                        */
194 enum
195 {
196     ZMQ_XREQ        = ZMQ_DEALER,
197     ZMQ_XREP        = ZMQ_ROUTER,
198 }
199 
200 /*  Socket options.                                                           */
201 enum ZMQ_AFFINITY = 4;
202 enum ZMQ_ROUTING_ID = 5;
203 enum ZMQ_SUBSCRIBE = 6;
204 enum ZMQ_UNSUBSCRIBE = 7;
205 enum ZMQ_RATE = 8;
206 enum ZMQ_RECOVERY_IVL = 9;
207 enum ZMQ_SNDBUF = 11;
208 enum ZMQ_RCVBUF = 12;
209 enum ZMQ_RCVMORE = 13;
210 enum ZMQ_FD = 14;
211 enum ZMQ_EVENTS = 15;
212 enum ZMQ_TYPE = 16;
213 enum ZMQ_LINGER = 17;
214 enum ZMQ_RECONNECT_IVL = 18;
215 enum ZMQ_BACKLOG = 19;
216 enum ZMQ_RECONNECT_IVL_MAX = 21;
217 enum ZMQ_MAXMSGSIZE = 22;
218 enum ZMQ_SNDHWM = 23;
219 enum ZMQ_RCVHWM = 24;
220 enum ZMQ_MULTICAST_HOPS = 25;
221 enum ZMQ_RCVTIMEO = 27;
222 enum ZMQ_SNDTIMEO = 28;
223 enum ZMQ_LAST_ENDPOINT = 32;
224 enum ZMQ_ROUTER_MANDATORY = 33;
225 enum ZMQ_TCP_KEEPALIVE = 34;
226 enum ZMQ_TCP_KEEPALIVE_CNT = 35;
227 enum ZMQ_TCP_KEEPALIVE_IDLE = 36;
228 enum ZMQ_TCP_KEEPALIVE_INTVL = 37;
229 enum ZMQ_IMMEDIATE = 39;
230 enum ZMQ_XPUB_VERBOSE = 40;
231 enum ZMQ_ROUTER_RAW = 41;
232 enum ZMQ_IPV6 = 42;
233 enum ZMQ_MECHANISM = 43;
234 enum ZMQ_PLAIN_SERVER = 44;
235 enum ZMQ_PLAIN_USERNAME = 45;
236 enum ZMQ_PLAIN_PASSWORD = 46;
237 enum ZMQ_CURVE_SERVER = 47;
238 enum ZMQ_CURVE_PUBLICKEY = 48;
239 enum ZMQ_CURVE_SECRETKEY = 49;
240 enum ZMQ_CURVE_SERVERKEY = 50;
241 enum ZMQ_PROBE_ROUTER = 51;
242 enum ZMQ_REQ_CORRELATE = 52;
243 enum ZMQ_REQ_RELAXED = 53;
244 enum ZMQ_CONFLATE = 54;
245 enum ZMQ_ZAP_DOMAIN = 55;
246 enum ZMQ_ROUTER_HANDOVER = 56;
247 enum ZMQ_TOS = 57;
248 enum ZMQ_CONNECT_ROUTING_ID = 61;
249 enum ZMQ_GSSAPI_SERVER = 62;
250 enum ZMQ_GSSAPI_PRINCIPAL = 63;
251 enum ZMQ_GSSAPI_SERVICE_PRINCIPAL= 64;
252 enum ZMQ_GSSAPI_PLAINTEXT = 65;
253 enum ZMQ_HANDSHAKE_IVL = 66;
254 enum ZMQ_SOCKS_PROXY = 68;
255 enum ZMQ_XPUB_NODROP = 69;
256 enum ZMQ_BLOCKY = 70;
257 enum ZMQ_XPUB_MANUAL = 71;
258 enum ZMQ_XPUB_WELCOME_MSG = 72;
259 enum ZMQ_STREAM_NOTIFY = 73;
260 enum ZMQ_INVERT_MATCHING = 74;
261 enum ZMQ_HEARTBEAT_IVL = 75;
262 enum ZMQ_HEARTBEAT_TTL = 76;
263 enum ZMQ_HEARTBEAT_TIMEOUT = 77;
264 enum ZMQ_XPUB_VERBOSER = 78;
265 enum ZMQ_CONNECT_TIMOUT = 79;
266 enum ZMQ_TCP_MAXRT = 80;
267 enum ZMQ_THREAD_SAFE = 81;
268 enum ZMQ_MULTICAST_MAXTPDU = 84;
269 enum ZMQ_VMCI_BUFFER_SIZE = 85;
270 enum ZMQ_VMCI_BUFFER_MIN_SIZE = 86;
271 enum ZMQ_VMCI_BUFFER_MAX_SIZE = 87;
272 enum ZMQ_VMCI_CONNECT_TIMEOUT = 88;
273 enum ZMQ_USE_FD = 89;
274 enum ZMQ_GSSAPI_PRINCIPAL_NAMETYPE = 90;
275 enum ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE = 91;
276 enum ZMQ_BINDTODEVICE = 92;
277 
278 
279 /*  Message options                                                           */
280 enum
281 {
282     ZMQ_MORE = 1,
283     ZMQ_SHARED = 3,
284 }
285 
286 /*  Send/recv options.                                                        */
287 enum
288 {
289     ZMQ_DONTWAIT = 1,
290     ZMQ_SNDMORE = 2
291 }
292 
293 /*  Security mechanisms                                                       */
294 enum
295 {
296     ZMQ_NULL = 0,
297     ZMQ_PLAIN = 1,
298     ZMQ_CURVE = 2,
299     ZMQ_GSSAPI = 3,
300 }
301 
302 /*  RADIO_DISH protocol                                                       */
303 enum ZMQ_GROUP_MAX_LENGTH = 15;
304 
305 /*  Deprecated options and aliases                                            */
306 enum ZMQ_IDENTITY = ZMQ_ROUTING_ID;
307 enum ZMQ_CONNECT_RID = ZMQ_CONNECT_ROUTING_ID;
308 enum ZMQ_TCP_ACCEPT_FILTER = 38;
309 enum ZMQ_IPC_FILTER_PID = 58;
310 enum ZMQ_IPC_FILTER_UID = 59;
311 enum ZMQ_IPC_FILTER_GID = 60;
312 enum ZMQ_IPV4ONLY = 31;
313 enum ZMQ_DELAY_ATTACH_ON_CONNECT = ZMQ_IMMEDIATE;
314 enum ZMQ_NOBLOCK = ZMQ_DONTWAIT;
315 enum ZMQ_FAIL_UNROUTABLE = ZMQ_ROUTER_MANDATORY;
316 enum ZMQ_ROUTER_BEHAVIOR = ZMQ_ROUTER_MANDATORY;
317 
318 /* Deprecated Message options                                                 */
319 enum ZMQ_SRCFD = 2;
320 
321 /******************************************************************************/
322 /*  GSSAPI definitions                                                        */
323 /******************************************************************************/
324 
325 /*  GSSAPI principal name types                                               */
326 enum ZMQ_GSSAPI_NT_HOSTBASED = 0;
327 enum ZMQ_GSSAPI_NT_USER_NAME = 1;
328 enum ZMQ_GSSAPI_NT_KRB5_PRINCIPAL = 2;
329 
330 /******************************************************************************/
331 /*  0MQ socket events and monitoring                                          */
332 /******************************************************************************/
333 
334 /*  Socket transport events (TCP, IPC, and TIPC only)                                */
335 
336 enum ZMQ_EVENT_CONNECTED = 0x0001;
337 enum ZMQ_EVENT_CONNECT_DELAYED = 0x0002;
338 enum ZMQ_EVENT_CONNECT_RETRIED = 0x0004;
339 enum ZMQ_EVENT_LISTENING = 0x0008;
340 enum ZMQ_EVENT_BIND_FAILED = 0x0010;
341 enum ZMQ_EVENT_ACCEPTED = 0x0020;
342 enum ZMQ_EVENT_ACCEPT_FAILED = 0x0040;
343 enum ZMQ_EVENT_CLOSED = 0x0080;
344 enum ZMQ_EVENT_CLOSE_FAILED = 0x0100;
345 enum ZMQ_EVENT_DISCONNECTED = 0x0200;
346 enum ZMQ_EVENT_MONITOR_STOPPED = 0x0400;
347 enum ZMQ_EVENT_ALL = 0xFFFF;
348 /*  Unspecified system errors during handshake. Event value is an errno.      */
349 enum ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL = 0x0800;
350 /*  Handshake complete successfully with successful authentication (if        *
351  *  enabled). Event value is unused.                                          */
352 enum ZMQ_EVENT_HANDSHAKE_SUCCEEDED = 0x1000;
353 /*  Protocol errors between ZMTP peers or between server and ZAP handler.     *
354  *  Event value is one of ZMQ_PROTOCOL_ERROR_*                                */
355 enum ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL = 0x2000;
356 /*  Failed authentication requests. Event value is the numeric ZAP status     *
357  *  code, i.e. 300, 400 or 500.                                               */
358 enum ZMQ_EVENT_HANDSHAKE_FAILED_AUTH = 0x4000;
359 enum ZMQ_PROTOCOL_ERROR_ZMTP_UNSPECIFIED = 0x10000000;
360 enum ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND = 0x10000001;
361 enum ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_SEQUENCE = 0x10000002;
362 enum ZMQ_PROTOCOL_ERROR_ZMTP_KEY_EXCHANGE = 0x10000003;
363 enum ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_UNSPECIFIED = 0x10000011;
364 enum ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_MESSAGE = 0x10000012;
365 enum ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO = 0x10000013;
366 enum ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_INITIATE = 0x10000014;
367 enum ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR = 0x10000015;
368 enum ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_READY = 0x10000016;
369 enum ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_WELCOME = 0x10000017;
370 enum ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_METADATA = 0x10000018;
371 // the following two may be due to erroneous configuration of a peer
372 enum ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC = 0x11000001;
373 enum ZMQ_PROTOCOL_ERROR_ZMTP_MECHANISM_MISMATCH = 0x11000002;
374 enum ZMQ_PROTOCOL_ERROR_ZAP_UNSPECIFIED = 0x20000000;
375 enum ZMQ_PROTOCOL_ERROR_ZAP_MALFORMED_REPLY = 0x20000001;
376 enum ZMQ_PROTOCOL_ERROR_ZAP_BAD_REQUEST_ID = 0x20000002;
377 enum ZMQ_PROTOCOL_ERROR_ZAP_BAD_VERSION = 0x20000003;
378 enum ZMQ_PROTOCOL_ERROR_ZAP_INVALID_STATUS_CODE = 0x20000004;
379 enum ZMQ_PROTOCOL_ERROR_ZAP_INVALID_METADATA = 0x20000005;
380 
381 void* zmq_socket(void*, int type_);
382 int zmq_close(void* s_);
383 int zmq_setsockopt(void* s_, int option_, const void* optval_, size_t optvallen_);
384 int zmq_getsockopt(void* s_, int option_, void* optval_, size_t *optvallen_);
385 int zmq_bind(void* s_, const char* addr_);
386 int zmq_connect(void* s_, const char* addr_);
387 int zmq_unbind(void* s_, const char* addr_);
388 int zmq_disconnect(void* s_, const char* addr_);
389 int zmq_send(void* s_, const void* buf_, size_t len_, int flags_);
390 int zmq_send_const(void *s_, const void* buf_, size_t len_, int flags_);
391 int zmq_recv(void* s_, void* buf_, size_t len_, int flags_);
392 int zmq_socket_monitor(void* s_, const char* addr_, int events_);
393 
394 
395 /******************************************************************************/
396 /*  Deprecated I/O multiplexing. Prefer using zmq_poller API                  */
397 /******************************************************************************/
398 
399 enum
400 {
401     ZMQ_POLLIN  = 1,
402     ZMQ_POLLOUT = 2,
403     ZMQ_POLLERR = 4,
404     ZMQ_POLLPRI = 8,
405 }
406 
407 struct zmq_pollitem_t
408 {
409     void* socket;
410     version (Windows)
411     {
412         import core.sys.windows.winsock2: SOCKET;
413         SOCKET fd;
414     }
415     else
416     {
417         int fd;
418     }
419     short events;
420     short revents;
421 }
422 
423 enum ZMQ_POLLITEMS_DFLT = 16;
424 
425 int zmq_poll(zmq_pollitem_t* items_, int nitems_, c_long timeout_);
426 
427 /******************************************************************************/
428 /*  Message proxying                                                          */
429 /******************************************************************************/
430 
431 int zmq_proxy(void* frontend_, void* backend_, void* capture_);
432 int zmq_proxy_steerable(void* frontend_,
433                         void* backend_,
434                         void* capture_,
435                         void* control_);
436 
437 /******************************************************************************/
438 /*  Probe library capabilities                                                */
439 /******************************************************************************/
440 
441 enum ZMQ_HAS_CAPABILITIES = 1;
442 int zmq_has(const(char)* capability_);
443 
444 /*  Deprecated aliases */
445 enum
446 {
447     ZMQ_STREAMER     = 1,
448     ZMQ_FORWARDER    = 2,
449     ZMQ_QUEUE        = 3
450 }
451 
452 /*  Deprecated methods */
453 int zmq_device(int type_, void* frontend_, void* backend_);
454 int zmq_sendmsg(void* s_, zmq_msg_t* msg_, int flags_);
455 int zmq_recvmsg(void* s_, zmq_msg_t* msg_, int flags_);
456 struct iovec;
457 int zmq_sendiov(void* s_, iovec* iov_, size_t count_, int flags_);
458 int zmq_recviov(void* s_, iovec* iov_, size_t* count_, int flags_);
459 
460 /******************************************************************************/
461 /*  Encryption functions                                                      */
462 /******************************************************************************/
463 
464 /*  Encode data with Z85 encoding. Returns encoded data                       */
465 char* zmq_z85_encode(char* dest_, const(ubyte)* data_, size_t size_);
466 
467 /*  Decode data with Z85 encoding. Returns decoded data                       */
468 ubyte* zmq_z85_decode(ubyte* dest_, const(char)* string_);
469 
470 /*  Generate z85-encoded public and private keypair with tweetnacl/libsodium. */
471 /*  Returns 0 on success.                                                     */
472 int zmq_curve_keypair(char* z85_public_key_, char* z85_secret_key_);
473 
474 /*  Derive the z85-encoded public key from the z85-encoded secret key.        */
475 /*  Returns 0 on success.                                                     */
476 int zmq_curve_public(char* z85_public_key_,
477                      const(char)* z85_secret_key_);
478 
479 /******************************************************************************/
480 /*  Atomic utility methods                                                    */
481 /******************************************************************************/
482 void* zmq_atomic_counter_new();
483 void zmq_atomic_counter_set(void* counter_, int value_);
484 int zmq_atomic_counter_inc(void* counter_);
485 int zmq_atomic_counter_dec(void* counter_);
486 int zmq_atomic_counter_value(void* counter_);
487 void zmq_atomic_counter_destroy(void** counter_p_);
488 
489 /******************************************************************************/
490 /*  Scheduling timers                                                         */
491 /******************************************************************************/
492 
493 enum ZMQ_HAVE_TIMERS = true;
494 
495 alias zmq_timer_fn = void function(int timer_id, void* arg);
496 
497 void* zmq_timers_new();
498 int zmq_timers_destroy(void** timers_p);
499 int zmq_timers_add(void* timers, size_t interval, zmq_timer_fn handler, void* arg);
500 int zmq_timers_cancel(void* timers, int timer_id);
501 int zmq_timers_set_interval(void* timers, int timer_id, size_t interval);
502 int zmq_timers_reset(void* timers, int timer_id);
503 c_long zmq_timers_timeout(void* timers);
504 int zmq_timers_execute(void* timers);
505 
506 
507 /******************************************************************************/
508 /*  These functions are not documented by man pages -- use at your own risk.  */
509 /*  If you need these to be part of the formal ZMQ API, then (a) write a man  */
510 /*  page, and (b) write a test case in tests.                                 */
511 /******************************************************************************/
512 
513 /*  Helper functions are used by perf tests so that they don't have to care   */
514 /*  about minutiae of time-related functions on different OS platforms.       */
515 
516 /*  Starts the stopwatch. Returns the handle to the watch.                    */
517 void* zmq_stopwatch_start();
518 
519 /*  Returns the number of microseconds elapsed since the stopwatch was        */
520 /*  started, but does not stop or deallocate the stopwatch.                   */
521 c_ulong zmq_stopwatch_intermediate(void* watch_);
522 
523 /*  Stops the stopwatch. Returns the number of microseconds elapsed since     */
524 /*  the stopwatch was started, and deallocates that watch.                    */
525 c_ulong zmq_stopwatch_stop(void* watch_);
526 
527 /*  Sleeps for specified number of seconds.                                   */
528 void zmq_sleep(int seconds_);
529 
530 /* Start a thread. Returns a handle to the thread.                            */
531 void* zmq_threadstart(void function(void*) nothrow func_, void* arg_);
532 
533 /* Wait for thread to complete then free up resources.                        */
534 void zmq_threadclose(void* thread_);
535 
536 
537 /******************************************************************************/
538 /*  These functions are DRAFT and disabled in stable releases, and subject to */
539 /*  change at ANY time until declared stable.                                 */
540 /******************************************************************************/
541 version(ZMQ_BUILD_DRAFT_API)
542 {
543 /*  DRAFT Socket types.                                                       */
544 enum
545 {
546     ZMQ_SERVER  = 12,
547     ZMQ_CLIENT  = 13,
548     ZMQ_RADIO   = 14,
549     ZMQ_DISH    = 15,
550     ZMQ_GATHER  = 16,
551     ZMQ_SCATTER = 17,
552     ZMQ_DGRAM   = 18,
553 }
554 
555 /*  DRAFT Socket options.                                                     */
556 enum ZMQ_ZAP_ENFORCE_DOMAIN = 93;
557 enum ZMQ_LOOPBACK_FASTPATH = 94;
558 enum ZMQ_METADATA = 95;
559 enum ZMQ_MULTICAST_LOOP = 96;
560 enum ZMQ_ROUTER_NOTIFY = 97;
561 enum ZMQ_XPUB_MANUAL_LAST_VALUE = 98;
562 enum ZMQ_SOCKS_USERNAME = 99;
563 enum ZMQ_SOCKS_PASSWORD = 100;
564 enum ZMQ_IN_BATCH_SIZE = 101;
565 enum ZMQ_OUT_BATCH_SIZE = 102;
566 
567 /*  DRAFT Context options                                                     */
568 enum ZMQ_ZERO_COPY_RECV = 10;
569 
570 /*  DRAFT Socket methods.                                                     */
571 int zmq_join(void* s, const(char)* group);
572 int zmq_leave(void* s, const(char)* group);
573 
574 /*  DRAFT Msg methods.                                                        */
575 int zmq_msg_set_routing_id(zmq_msg_t* msg, uint routing_id);
576 uint zmq_msg_routing_id(zmq_msg_t* msg);
577 int zmq_msg_set_group(zmq_msg_t* msg, const(char)* group);
578 const(char)* zmq_msg_group(zmq_msg_t* msg);
579 
580 /*  DRAFT Msg property names.                                                 */
581 enum ZMQ_MSG_PROPERTY_ROUTING_ID = "Routing-Id";
582 enum ZMQ_MSG_PROPERTY_SOCKET_TYPE = "Socket-Type";
583 enum ZMQ_MSG_PROPERTY_USER_ID = "User-Id";
584 enum ZMQ_MSG_PROPERTY_PEER_ADDRESS = "Peer-Address";
585 
586 /*  Router notify options                                                     */
587 enum ZMQ_NOTIFY_CONNECT = 1;
588 enum ZMQ_NOTIFY_DISCONNECT = 2;
589 
590 /******************************************************************************/
591 /*  Poller polling on sockets,fd, and thread-safe sockets                     */
592 /******************************************************************************/
593 
594 version(Windows)
595 {
596     alias zmq_fd_t = SOCKET;
597 }
598 else
599 {
600     alias zmq_fd_t = int;
601 }
602 
603 struct zmq_poller_event_t
604 {
605     void* socket;
606     zmq_fd_t fd;
607     void* user_data;
608     short events;
609 }
610 
611 void* zmq_poller_new();
612 int zmq_poller_destroy(void** poller_p);
613 int zmq_poller_add(void* poller, void* socket, void* user_data, short events);
614 int zmq_poller_modify(void* poller, void* socket, short events);
615 int zmq_poller_remove(void* poller, void* socket);
616 int zmq_poller_wait(void* poller, zmq_poller_event_t* event, c_long timeout);
617 int zmq_poller_wait_all(void* poller,
618                         zmq_poller_event_t* events,
619                         int n_events,
620                         c_long timout);
621 int zmq_poller_fd(void* poller, zmq_fd_t* fd);
622 
623 int zmq_poller_add_fd(void* poller, zmq_fd_t fd, void* user_data, short events);
624 int zmq_poller_modify_fd(void* poller, zmq_fd_t fd, short events);
625 int zmq_poller_remove_fd(void* poller, zmq_fd_t fd);
626 
627 int zmq_socket_get_peer_state(void* socket,
628                               const(void)* routing_id,
629                               size_t routing_id_size);
630 
631 /*  DRAFT Socket monitoring events                                            */
632 enum ZMQ_EVENT_PIPES_STATS = 0x10000;
633 
634 enum ZMQ_CURRENT_EVENT_VERSION = 1;
635 enum ZMQ_CURRENT_EVENT_VERSION_DRAFT = 2;
636 
637 enum ZMQ_EVENT_ALL_V1 = ZMQ_EVENT_ALL;
638 enum ZMQ_EVENT_ALL_V2 = ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS;
639 
640 int zmq_socket_monitor_versioned(
641   void* s_, const(char)* addr_, ulong events_, int event_version_, int type_);
642 int zmq_socket_monitor_pipes_stats(void* s);
643 
644 } // version(ZMQ_BUILD_DRAFT_API)
645 
646 }// extern (C)