| 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 | |
| 38 | #ifndef __ZMQ_H_INCLUDED__ |
| 39 | #define __ZMQ_H_INCLUDED__ |
| 40 | |
| 41 | /* Version macros for compile-time API version detection */ |
| 42 | #define ZMQ_VERSION_MAJOR 4 |
| 43 | #define ZMQ_VERSION_MINOR 3 |
| 44 | #define ZMQ_VERSION_PATCH 3 |
| 45 | |
| 46 | #define ZMQ_MAKE_VERSION(major, minor, patch) \ |
| 47 | ((major) *10000 + (minor) *100 + (patch)) |
| 48 | #define ZMQ_VERSION \ |
| 49 | ZMQ_MAKE_VERSION (ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH) |
| 50 | |
| 51 | #ifdef __cplusplus |
| 52 | extern "C" { |
| 53 | #endif |
| 54 | |
| 55 | #if !defined _WIN32_WCE |
| 56 | #include <errno.h> |
| 57 | #endif |
| 58 | #include <stddef.h> |
| 59 | #include <stdio.h> |
| 60 | #if defined _WIN32 |
| 61 | // Set target version to Windows Server 2008, Windows Vista or higher. |
| 62 | // Windows XP (0x0501) is supported but without client & server socket types. |
| 63 | #ifndef _WIN32_WINNT |
| 64 | #define _WIN32_WINNT 0x0600 |
| 65 | #endif |
| 66 | |
| 67 | #ifdef __MINGW32__ |
| 68 | // Require Windows XP or higher with MinGW for getaddrinfo(). |
| 69 | #if (_WIN32_WINNT >= 0x0501) |
| 70 | #else |
| 71 | #error You need at least Windows XP target |
| 72 | #endif |
| 73 | #endif |
| 74 | #endif |
| 75 | |
| 76 | /* Handle DSO symbol visibility */ |
| 77 | #if defined _WIN32 |
| 78 | #if defined ZMQ_STATIC |
| 79 | #define ZMQ_EXPORT |
| 80 | #elif defined DLL_EXPORT |
| 81 | #define ZMQ_EXPORT __declspec(dllexport) |
| 82 | #else |
| 83 | #define ZMQ_EXPORT __declspec(dllimport) |
| 84 | #endif |
| 85 | #else |
| 86 | #if defined __SUNPRO_C || defined __SUNPRO_CC |
| 87 | #define ZMQ_EXPORT __global |
| 88 | #elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER |
| 89 | #define ZMQ_EXPORT __attribute__ ((visibility ("default"))) |
| 90 | #else |
| 91 | #define ZMQ_EXPORT |
| 92 | #endif |
| 93 | #endif |
| 94 | |
| 95 | /* Define integer types needed for event interface */ |
| 96 | #define ZMQ_DEFINED_STDINT 1 |
| 97 | #if defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_OPENVMS |
| 98 | #include <inttypes.h> |
| 99 | #elif defined _MSC_VER && _MSC_VER < 1600 |
| 100 | #ifndef uint64_t |
| 101 | typedef unsigned __int64 uint64_t; |
| 102 | #endif |
| 103 | #ifndef int32_t |
| 104 | typedef __int32 int32_t; |
| 105 | #endif |
| 106 | #ifndef uint32_t |
| 107 | typedef unsigned __int32 uint32_t; |
| 108 | #endif |
| 109 | #ifndef uint16_t |
| 110 | typedef unsigned __int16 uint16_t; |
| 111 | #endif |
| 112 | #ifndef uint8_t |
| 113 | typedef unsigned __int8 uint8_t; |
| 114 | #endif |
| 115 | #else |
| 116 | #include <stdint.h> |
| 117 | #endif |
| 118 | |
| 119 | // 32-bit AIX's pollfd struct members are called reqevents and rtnevents so it |
| 120 | // defines compatibility macros for them. Need to include that header first to |
| 121 | // stop build failures since zmq_pollset_t defines them as events and revents. |
| 122 | #ifdef ZMQ_HAVE_AIX |
| 123 | #include <poll.h> |
| 124 | #endif |
| 125 | |
| 126 | |
| 127 | /******************************************************************************/ |
| 128 | /* 0MQ errors. */ |
| 129 | /******************************************************************************/ |
| 130 | |
| 131 | /* A number random enough not to collide with different errno ranges on */ |
| 132 | /* different OSes. The assumption is that error_t is at least 32-bit type. */ |
| 133 | #define ZMQ_HAUSNUMERO 156384712 |
| 134 | |
| 135 | /* On Windows platform some of the standard POSIX errnos are not defined. */ |
| 136 | #ifndef ENOTSUP |
| 137 | #define ENOTSUP (ZMQ_HAUSNUMERO + 1) |
| 138 | #endif |
| 139 | #ifndef EPROTONOSUPPORT |
| 140 | #define EPROTONOSUPPORT (ZMQ_HAUSNUMERO + 2) |
| 141 | #endif |
| 142 | #ifndef ENOBUFS |
| 143 | #define ENOBUFS (ZMQ_HAUSNUMERO + 3) |
| 144 | #endif |
| 145 | #ifndef ENETDOWN |
| 146 | #define ENETDOWN (ZMQ_HAUSNUMERO + 4) |
| 147 | #endif |
| 148 | #ifndef EADDRINUSE |
| 149 | #define EADDRINUSE (ZMQ_HAUSNUMERO + 5) |
| 150 | #endif |
| 151 | #ifndef EADDRNOTAVAIL |
| 152 | #define EADDRNOTAVAIL (ZMQ_HAUSNUMERO + 6) |
| 153 | #endif |
| 154 | #ifndef ECONNREFUSED |
| 155 | #define ECONNREFUSED (ZMQ_HAUSNUMERO + 7) |
| 156 | #endif |
| 157 | #ifndef EINPROGRESS |
| 158 | #define EINPROGRESS (ZMQ_HAUSNUMERO + 8) |
| 159 | #endif |
| 160 | #ifndef ENOTSOCK |
| 161 | #define ENOTSOCK (ZMQ_HAUSNUMERO + 9) |
| 162 | #endif |
| 163 | #ifndef EMSGSIZE |
| 164 | #define EMSGSIZE (ZMQ_HAUSNUMERO + 10) |
| 165 | #endif |
| 166 | #ifndef EAFNOSUPPORT |
| 167 | #define EAFNOSUPPORT (ZMQ_HAUSNUMERO + 11) |
| 168 | #endif |
| 169 | #ifndef ENETUNREACH |
| 170 | #define ENETUNREACH (ZMQ_HAUSNUMERO + 12) |
| 171 | #endif |
| 172 | #ifndef ECONNABORTED |
| 173 | #define ECONNABORTED (ZMQ_HAUSNUMERO + 13) |
| 174 | #endif |
| 175 | #ifndef ECONNRESET |
| 176 | #define ECONNRESET (ZMQ_HAUSNUMERO + 14) |
| 177 | #endif |
| 178 | #ifndef ENOTCONN |
| 179 | #define ENOTCONN (ZMQ_HAUSNUMERO + 15) |
| 180 | #endif |
| 181 | #ifndef ETIMEDOUT |
| 182 | #define ETIMEDOUT (ZMQ_HAUSNUMERO + 16) |
| 183 | #endif |
| 184 | #ifndef EHOSTUNREACH |
| 185 | #define EHOSTUNREACH (ZMQ_HAUSNUMERO + 17) |
| 186 | #endif |
| 187 | #ifndef ENETRESET |
| 188 | #define ENETRESET (ZMQ_HAUSNUMERO + 18) |
| 189 | #endif |
| 190 | |
| 191 | /* Native 0MQ error codes. */ |
| 192 | #define EFSM (ZMQ_HAUSNUMERO + 51) |
| 193 | #define ENOCOMPATPROTO (ZMQ_HAUSNUMERO + 52) |
| 194 | #define ETERM (ZMQ_HAUSNUMERO + 53) |
| 195 | #define EMTHREAD (ZMQ_HAUSNUMERO + 54) |
| 196 | |
| 197 | /* This function retrieves the errno as it is known to 0MQ library. The goal */ |
| 198 | /* of this function is to make the code 100% portable, including where 0MQ */ |
| 199 | /* compiled with certain CRT library (on Windows) is linked to an */ |
| 200 | /* application that uses different CRT library. */ |
| 201 | ZMQ_EXPORT int zmq_errno (void); |
| 202 | |
| 203 | /* Resolves system errors and 0MQ errors to human-readable string. */ |
| 204 | ZMQ_EXPORT const char *zmq_strerror (int errnum_); |
| 205 | |
| 206 | /* Run-time API version detection */ |
| 207 | ZMQ_EXPORT void zmq_version (int *major_, int *minor_, int *patch_); |
| 208 | |
| 209 | /******************************************************************************/ |
| 210 | /* 0MQ infrastructure (a.k.a. context) initialisation & termination. */ |
| 211 | /******************************************************************************/ |
| 212 | |
| 213 | /* Context options */ |
| 214 | #define ZMQ_IO_THREADS 1 |
| 215 | #define ZMQ_MAX_SOCKETS 2 |
| 216 | #define ZMQ_SOCKET_LIMIT 3 |
| 217 | #define ZMQ_THREAD_PRIORITY 3 |
| 218 | #define ZMQ_THREAD_SCHED_POLICY 4 |
| 219 | #define ZMQ_MAX_MSGSZ 5 |
| 220 | #define ZMQ_MSG_T_SIZE 6 |
| 221 | #define ZMQ_THREAD_AFFINITY_CPU_ADD 7 |
| 222 | #define ZMQ_THREAD_AFFINITY_CPU_REMOVE 8 |
| 223 | #define ZMQ_THREAD_NAME_PREFIX 9 |
| 224 | |
| 225 | /* Default for new contexts */ |
| 226 | #define ZMQ_IO_THREADS_DFLT 1 |
| 227 | #define ZMQ_MAX_SOCKETS_DFLT 1023 |
| 228 | #define ZMQ_THREAD_PRIORITY_DFLT -1 |
| 229 | #define ZMQ_THREAD_SCHED_POLICY_DFLT -1 |
| 230 | |
| 231 | ZMQ_EXPORT void *zmq_ctx_new (void); |
| 232 | ZMQ_EXPORT int zmq_ctx_term (void *context_); |
| 233 | ZMQ_EXPORT int zmq_ctx_shutdown (void *context_); |
| 234 | ZMQ_EXPORT int zmq_ctx_set (void *context_, int option_, int optval_); |
| 235 | ZMQ_EXPORT int zmq_ctx_get (void *context_, int option_); |
| 236 | |
| 237 | /* Old (legacy) API */ |
| 238 | ZMQ_EXPORT void *zmq_init (int io_threads_); |
| 239 | ZMQ_EXPORT int zmq_term (void *context_); |
| 240 | ZMQ_EXPORT int zmq_ctx_destroy (void *context_); |
| 241 | |
| 242 | |
| 243 | /******************************************************************************/ |
| 244 | /* 0MQ message definition. */ |
| 245 | /******************************************************************************/ |
| 246 | |
| 247 | /* Some architectures, like sparc64 and some variants of aarch64, enforce pointer |
| 248 | * alignment and raise sigbus on violations. Make sure applications allocate |
| 249 | * zmq_msg_t on addresses aligned on a pointer-size boundary to avoid this issue. |
| 250 | */ |
| 251 | typedef struct zmq_msg_t |
| 252 | { |
| 253 | #if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64)) |
| 254 | __declspec(align (8)) unsigned char _[64]; |
| 255 | #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_ARM_ARMV7VE)) |
| 256 | __declspec(align (4)) unsigned char _[64]; |
| 257 | #elif defined(__GNUC__) || defined(__INTEL_COMPILER) \ |
| 258 | || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x590) \ |
| 259 | || (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x590) |
| 260 | unsigned char _[64] __attribute__ ((aligned (sizeof (void *)))); |
| 261 | #else |
| 262 | unsigned char _[64]; |
| 263 | #endif |
| 264 | } zmq_msg_t; |
| 265 | |
| 266 | typedef void(zmq_free_fn) (void *data_, void *hint_); |
| 267 | |
| 268 | ZMQ_EXPORT int zmq_msg_init (zmq_msg_t *msg_); |
| 269 | ZMQ_EXPORT int zmq_msg_init_size (zmq_msg_t *msg_, size_t size_); |
| 270 | ZMQ_EXPORT int zmq_msg_init_data ( |
| 271 | zmq_msg_t *msg_, void *data_, size_t size_, zmq_free_fn *ffn_, void *hint_); |
| 272 | ZMQ_EXPORT int zmq_msg_send (zmq_msg_t *msg_, void *s_, int flags_); |
| 273 | ZMQ_EXPORT int zmq_msg_recv (zmq_msg_t *msg_, void *s_, int flags_); |
| 274 | ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg_); |
| 275 | ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest_, zmq_msg_t *src_); |
| 276 | ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest_, zmq_msg_t *src_); |
| 277 | ZMQ_EXPORT void *zmq_msg_data (zmq_msg_t *msg_); |
| 278 | ZMQ_EXPORT size_t zmq_msg_size (const zmq_msg_t *msg_); |
| 279 | ZMQ_EXPORT int zmq_msg_more (const zmq_msg_t *msg_); |
| 280 | ZMQ_EXPORT int zmq_msg_get (const zmq_msg_t *msg_, int property_); |
| 281 | ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg_, int property_, int optval_); |
| 282 | ZMQ_EXPORT const char *zmq_msg_gets (const zmq_msg_t *msg_, |
| 283 | const char *property_); |
| 284 | |
| 285 | /******************************************************************************/ |
| 286 | /* 0MQ socket definition. */ |
| 287 | /******************************************************************************/ |
| 288 | |
| 289 | /* Socket types. */ |
| 290 | #define ZMQ_PAIR 0 |
| 291 | #define ZMQ_PUB 1 |
| 292 | #define ZMQ_SUB 2 |
| 293 | #define ZMQ_REQ 3 |
| 294 | #define ZMQ_REP 4 |
| 295 | #define ZMQ_DEALER 5 |
| 296 | #define ZMQ_ROUTER 6 |
| 297 | #define ZMQ_PULL 7 |
| 298 | #define ZMQ_PUSH 8 |
| 299 | #define ZMQ_XPUB 9 |
| 300 | #define ZMQ_XSUB 10 |
| 301 | #define ZMQ_STREAM 11 |
| 302 | |
| 303 | /* Deprecated aliases */ |
| 304 | #define ZMQ_XREQ ZMQ_DEALER |
| 305 | #define ZMQ_XREP ZMQ_ROUTER |
| 306 | |
| 307 | /* Socket options. */ |
| 308 | #define ZMQ_AFFINITY 4 |
| 309 | #define ZMQ_ROUTING_ID 5 |
| 310 | #define ZMQ_SUBSCRIBE 6 |
| 311 | #define ZMQ_UNSUBSCRIBE 7 |
| 312 | #define ZMQ_RATE 8 |
| 313 | #define ZMQ_RECOVERY_IVL 9 |
| 314 | #define ZMQ_SNDBUF 11 |
| 315 | #define ZMQ_RCVBUF 12 |
| 316 | #define ZMQ_RCVMORE 13 |
| 317 | #define ZMQ_FD 14 |
| 318 | #define ZMQ_EVENTS 15 |
| 319 | #define ZMQ_TYPE 16 |
| 320 | #define ZMQ_LINGER 17 |
| 321 | #define ZMQ_RECONNECT_IVL 18 |
| 322 | #define ZMQ_BACKLOG 19 |
| 323 | #define ZMQ_RECONNECT_IVL_MAX 21 |
| 324 | #define ZMQ_MAXMSGSIZE 22 |
| 325 | #define ZMQ_SNDHWM 23 |
| 326 | #define ZMQ_RCVHWM 24 |
| 327 | #define ZMQ_MULTICAST_HOPS 25 |
| 328 | #define ZMQ_RCVTIMEO 27 |
| 329 | #define ZMQ_SNDTIMEO 28 |
| 330 | #define ZMQ_LAST_ENDPOINT 32 |
| 331 | #define ZMQ_ROUTER_MANDATORY 33 |
| 332 | #define ZMQ_TCP_KEEPALIVE 34 |
| 333 | #define ZMQ_TCP_KEEPALIVE_CNT 35 |
| 334 | #define ZMQ_TCP_KEEPALIVE_IDLE 36 |
| 335 | #define ZMQ_TCP_KEEPALIVE_INTVL 37 |
| 336 | #define ZMQ_IMMEDIATE 39 |
| 337 | #define ZMQ_XPUB_VERBOSE 40 |
| 338 | #define ZMQ_ROUTER_RAW 41 |
| 339 | #define ZMQ_IPV6 42 |
| 340 | #define ZMQ_MECHANISM 43 |
| 341 | #define ZMQ_PLAIN_SERVER 44 |
| 342 | #define ZMQ_PLAIN_USERNAME 45 |
| 343 | #define ZMQ_PLAIN_PASSWORD 46 |
| 344 | #define ZMQ_CURVE_SERVER 47 |
| 345 | #define ZMQ_CURVE_PUBLICKEY 48 |
| 346 | #define ZMQ_CURVE_SECRETKEY 49 |
| 347 | #define ZMQ_CURVE_SERVERKEY 50 |
| 348 | #define ZMQ_PROBE_ROUTER 51 |
| 349 | #define ZMQ_REQ_CORRELATE 52 |
| 350 | #define ZMQ_REQ_RELAXED 53 |
| 351 | #define ZMQ_CONFLATE 54 |
| 352 | #define ZMQ_ZAP_DOMAIN 55 |
| 353 | #define ZMQ_ROUTER_HANDOVER 56 |
| 354 | #define ZMQ_TOS 57 |
| 355 | #define ZMQ_CONNECT_ROUTING_ID 61 |
| 356 | #define ZMQ_GSSAPI_SERVER 62 |
| 357 | #define ZMQ_GSSAPI_PRINCIPAL 63 |
| 358 | #define ZMQ_GSSAPI_SERVICE_PRINCIPAL 64 |
| 359 | #define ZMQ_GSSAPI_PLAINTEXT 65 |
| 360 | #define ZMQ_HANDSHAKE_IVL 66 |
| 361 | #define ZMQ_SOCKS_PROXY 68 |
| 362 | #define ZMQ_XPUB_NODROP 69 |
| 363 | #define ZMQ_BLOCKY 70 |
| 364 | #define ZMQ_XPUB_MANUAL 71 |
| 365 | #define ZMQ_XPUB_WELCOME_MSG 72 |
| 366 | #define ZMQ_STREAM_NOTIFY 73 |
| 367 | #define ZMQ_INVERT_MATCHING 74 |
| 368 | #define ZMQ_HEARTBEAT_IVL 75 |
| 369 | #define ZMQ_HEARTBEAT_TTL 76 |
| 370 | #define ZMQ_HEARTBEAT_TIMEOUT 77 |
| 371 | #define ZMQ_XPUB_VERBOSER 78 |
| 372 | #define ZMQ_CONNECT_TIMEOUT 79 |
| 373 | #define ZMQ_TCP_MAXRT 80 |
| 374 | #define ZMQ_THREAD_SAFE 81 |
| 375 | #define ZMQ_MULTICAST_MAXTPDU 84 |
| 376 | #define ZMQ_VMCI_BUFFER_SIZE 85 |
| 377 | #define ZMQ_VMCI_BUFFER_MIN_SIZE 86 |
| 378 | #define ZMQ_VMCI_BUFFER_MAX_SIZE 87 |
| 379 | #define ZMQ_VMCI_CONNECT_TIMEOUT 88 |
| 380 | #define ZMQ_USE_FD 89 |
| 381 | #define ZMQ_GSSAPI_PRINCIPAL_NAMETYPE 90 |
| 382 | #define ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE 91 |
| 383 | #define ZMQ_BINDTODEVICE 92 |
| 384 | |
| 385 | /* Message options */ |
| 386 | #define ZMQ_MORE 1 |
| 387 | #define ZMQ_SHARED 3 |
| 388 | |
| 389 | /* Send/recv options. */ |
| 390 | #define ZMQ_DONTWAIT 1 |
| 391 | #define ZMQ_SNDMORE 2 |
| 392 | |
| 393 | /* Security mechanisms */ |
| 394 | #define ZMQ_NULL 0 |
| 395 | #define ZMQ_PLAIN 1 |
| 396 | #define ZMQ_CURVE 2 |
| 397 | #define ZMQ_GSSAPI 3 |
| 398 | |
| 399 | /* RADIO-DISH protocol */ |
| 400 | #define ZMQ_GROUP_MAX_LENGTH 15 |
| 401 | |
| 402 | /* Deprecated options and aliases */ |
| 403 | #define ZMQ_IDENTITY ZMQ_ROUTING_ID |
| 404 | #define ZMQ_CONNECT_RID ZMQ_CONNECT_ROUTING_ID |
| 405 | #define ZMQ_TCP_ACCEPT_FILTER 38 |
| 406 | #define ZMQ_IPC_FILTER_PID 58 |
| 407 | #define ZMQ_IPC_FILTER_UID 59 |
| 408 | #define ZMQ_IPC_FILTER_GID 60 |
| 409 | #define ZMQ_IPV4ONLY 31 |
| 410 | #define ZMQ_DELAY_ATTACH_ON_CONNECT ZMQ_IMMEDIATE |
| 411 | #define ZMQ_NOBLOCK ZMQ_DONTWAIT |
| 412 | #define ZMQ_FAIL_UNROUTABLE ZMQ_ROUTER_MANDATORY |
| 413 | #define ZMQ_ROUTER_BEHAVIOR ZMQ_ROUTER_MANDATORY |
| 414 | |
| 415 | /* Deprecated Message options */ |
| 416 | #define ZMQ_SRCFD 2 |
| 417 | |
| 418 | /******************************************************************************/ |
| 419 | /* GSSAPI definitions */ |
| 420 | /******************************************************************************/ |
| 421 | |
| 422 | /* GSSAPI principal name types */ |
| 423 | #define ZMQ_GSSAPI_NT_HOSTBASED 0 |
| 424 | #define ZMQ_GSSAPI_NT_USER_NAME 1 |
| 425 | #define ZMQ_GSSAPI_NT_KRB5_PRINCIPAL 2 |
| 426 | |
| 427 | /******************************************************************************/ |
| 428 | /* 0MQ socket events and monitoring */ |
| 429 | /******************************************************************************/ |
| 430 | |
| 431 | /* Socket transport events (TCP, IPC and TIPC only) */ |
| 432 | |
| 433 | #define ZMQ_EVENT_CONNECTED 0x0001 |
| 434 | #define ZMQ_EVENT_CONNECT_DELAYED 0x0002 |
| 435 | #define ZMQ_EVENT_CONNECT_RETRIED 0x0004 |
| 436 | #define ZMQ_EVENT_LISTENING 0x0008 |
| 437 | #define ZMQ_EVENT_BIND_FAILED 0x0010 |
| 438 | #define ZMQ_EVENT_ACCEPTED 0x0020 |
| 439 | #define ZMQ_EVENT_ACCEPT_FAILED 0x0040 |
| 440 | #define ZMQ_EVENT_CLOSED 0x0080 |
| 441 | #define ZMQ_EVENT_CLOSE_FAILED 0x0100 |
| 442 | #define ZMQ_EVENT_DISCONNECTED 0x0200 |
| 443 | #define ZMQ_EVENT_MONITOR_STOPPED 0x0400 |
| 444 | #define ZMQ_EVENT_ALL 0xFFFF |
| 445 | /* Unspecified system errors during handshake. Event value is an errno. */ |
| 446 | #define ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL 0x0800 |
| 447 | /* Handshake complete successfully with successful authentication (if * |
| 448 | * enabled). Event value is unused. */ |
| 449 | #define ZMQ_EVENT_HANDSHAKE_SUCCEEDED 0x1000 |
| 450 | /* Protocol errors between ZMTP peers or between server and ZAP handler. * |
| 451 | * Event value is one of ZMQ_PROTOCOL_ERROR_* */ |
| 452 | #define ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL 0x2000 |
| 453 | /* Failed authentication requests. Event value is the numeric ZAP status * |
| 454 | * code, i.e. 300, 400 or 500. */ |
| 455 | #define ZMQ_EVENT_HANDSHAKE_FAILED_AUTH 0x4000 |
| 456 | #define ZMQ_PROTOCOL_ERROR_ZMTP_UNSPECIFIED 0x10000000 |
| 457 | #define ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND 0x10000001 |
| 458 | #define ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_SEQUENCE 0x10000002 |
| 459 | #define ZMQ_PROTOCOL_ERROR_ZMTP_KEY_EXCHANGE 0x10000003 |
| 460 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_UNSPECIFIED 0x10000011 |
| 461 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_MESSAGE 0x10000012 |
| 462 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO 0x10000013 |
| 463 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_INITIATE 0x10000014 |
| 464 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR 0x10000015 |
| 465 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_READY 0x10000016 |
| 466 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_WELCOME 0x10000017 |
| 467 | #define ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_METADATA 0x10000018 |
| 468 | // the following two may be due to erroneous configuration of a peer |
| 469 | #define ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC 0x11000001 |
| 470 | #define ZMQ_PROTOCOL_ERROR_ZMTP_MECHANISM_MISMATCH 0x11000002 |
| 471 | #define ZMQ_PROTOCOL_ERROR_ZAP_UNSPECIFIED 0x20000000 |
| 472 | #define ZMQ_PROTOCOL_ERROR_ZAP_MALFORMED_REPLY 0x20000001 |
| 473 | #define ZMQ_PROTOCOL_ERROR_ZAP_BAD_REQUEST_ID 0x20000002 |
| 474 | #define ZMQ_PROTOCOL_ERROR_ZAP_BAD_VERSION 0x20000003 |
| 475 | #define ZMQ_PROTOCOL_ERROR_ZAP_INVALID_STATUS_CODE 0x20000004 |
| 476 | #define ZMQ_PROTOCOL_ERROR_ZAP_INVALID_METADATA 0x20000005 |
| 477 | #define ZMQ_PROTOCOL_ERROR_WS_UNSPECIFIED 0x30000000 |
| 478 | |
| 479 | ZMQ_EXPORT void *zmq_socket (void *, int type_); |
| 480 | ZMQ_EXPORT int zmq_close (void *s_); |
| 481 | ZMQ_EXPORT int |
| 482 | zmq_setsockopt (void *s_, int option_, const void *optval_, size_t optvallen_); |
| 483 | ZMQ_EXPORT int |
| 484 | zmq_getsockopt (void *s_, int option_, void *optval_, size_t *optvallen_); |
| 485 | ZMQ_EXPORT int zmq_bind (void *s_, const char *addr_); |
| 486 | ZMQ_EXPORT int zmq_connect (void *s_, const char *addr_); |
| 487 | ZMQ_EXPORT int zmq_unbind (void *s_, const char *addr_); |
| 488 | ZMQ_EXPORT int zmq_disconnect (void *s_, const char *addr_); |
| 489 | ZMQ_EXPORT int zmq_send (void *s_, const void *buf_, size_t len_, int flags_); |
| 490 | ZMQ_EXPORT int |
| 491 | zmq_send_const (void *s_, const void *buf_, size_t len_, int flags_); |
| 492 | ZMQ_EXPORT int zmq_recv (void *s_, void *buf_, size_t len_, int flags_); |
| 493 | ZMQ_EXPORT int zmq_socket_monitor (void *s_, const char *addr_, int events_); |
| 494 | |
| 495 | /******************************************************************************/ |
| 496 | /* Hide socket fd type; this was before zmq_poller_event_t typedef below */ |
| 497 | /******************************************************************************/ |
| 498 | |
| 499 | #if defined _WIN32 |
| 500 | // Windows uses a pointer-sized unsigned integer to store the socket fd. |
| 501 | #if defined _WIN64 |
| 502 | typedef unsigned __int64 zmq_fd_t; |
| 503 | #else |
| 504 | typedef unsigned int zmq_fd_t; |
| 505 | #endif |
| 506 | #else |
| 507 | typedef int zmq_fd_t; |
| 508 | #endif |
| 509 | |
| 510 | /******************************************************************************/ |
| 511 | /* Deprecated I/O multiplexing. Prefer using zmq_poller API */ |
| 512 | /******************************************************************************/ |
| 513 | |
| 514 | #define ZMQ_POLLIN 1 |
| 515 | #define ZMQ_POLLOUT 2 |
| 516 | #define ZMQ_POLLERR 4 |
| 517 | #define ZMQ_POLLPRI 8 |
| 518 | |
| 519 | typedef struct zmq_pollitem_t |
| 520 | { |
| 521 | void *socket; |
| 522 | zmq_fd_t fd; |
| 523 | short events; |
| 524 | short revents; |
| 525 | } zmq_pollitem_t; |
| 526 | |
| 527 | #define ZMQ_POLLITEMS_DFLT 16 |
| 528 | |
| 529 | ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_); |
| 530 | |
| 531 | /******************************************************************************/ |
| 532 | /* Message proxying */ |
| 533 | /******************************************************************************/ |
| 534 | |
| 535 | ZMQ_EXPORT int zmq_proxy (void *frontend_, void *backend_, void *capture_); |
| 536 | ZMQ_EXPORT int zmq_proxy_steerable (void *frontend_, |
| 537 | void *backend_, |
| 538 | void *capture_, |
| 539 | void *control_); |
| 540 | |
| 541 | /******************************************************************************/ |
| 542 | /* Probe library capabilities */ |
| 543 | /******************************************************************************/ |
| 544 | |
| 545 | #define ZMQ_HAS_CAPABILITIES 1 |
| 546 | ZMQ_EXPORT int zmq_has (const char *capability_); |
| 547 | |
| 548 | /* Deprecated aliases */ |
| 549 | #define ZMQ_STREAMER 1 |
| 550 | #define ZMQ_FORWARDER 2 |
| 551 | #define ZMQ_QUEUE 3 |
| 552 | |
| 553 | /* Deprecated methods */ |
| 554 | ZMQ_EXPORT int zmq_device (int type_, void *frontend_, void *backend_); |
| 555 | ZMQ_EXPORT int zmq_sendmsg (void *s_, zmq_msg_t *msg_, int flags_); |
| 556 | ZMQ_EXPORT int zmq_recvmsg (void *s_, zmq_msg_t *msg_, int flags_); |
| 557 | struct iovec; |
| 558 | ZMQ_EXPORT int |
| 559 | zmq_sendiov (void *s_, struct iovec *iov_, size_t count_, int flags_); |
| 560 | ZMQ_EXPORT int |
| 561 | zmq_recviov (void *s_, struct iovec *iov_, size_t *count_, int flags_); |
| 562 | |
| 563 | /******************************************************************************/ |
| 564 | /* Encryption functions */ |
| 565 | /******************************************************************************/ |
| 566 | |
| 567 | /* Encode data with Z85 encoding. Returns encoded data */ |
| 568 | ZMQ_EXPORT char * |
| 569 | zmq_z85_encode (char *dest_, const uint8_t *data_, size_t size_); |
| 570 | |
| 571 | /* Decode data with Z85 encoding. Returns decoded data */ |
| 572 | ZMQ_EXPORT uint8_t *zmq_z85_decode (uint8_t *dest_, const char *string_); |
| 573 | |
| 574 | /* Generate z85-encoded public and private keypair with tweetnacl/libsodium. */ |
| 575 | /* Returns 0 on success. */ |
| 576 | ZMQ_EXPORT int zmq_curve_keypair (char *z85_public_key_, char *z85_secret_key_); |
| 577 | |
| 578 | /* Derive the z85-encoded public key from the z85-encoded secret key. */ |
| 579 | /* Returns 0 on success. */ |
| 580 | ZMQ_EXPORT int zmq_curve_public (char *z85_public_key_, |
| 581 | const char *z85_secret_key_); |
| 582 | |
| 583 | /******************************************************************************/ |
| 584 | /* Atomic utility methods */ |
| 585 | /******************************************************************************/ |
| 586 | |
| 587 | ZMQ_EXPORT void *zmq_atomic_counter_new (void); |
| 588 | ZMQ_EXPORT void zmq_atomic_counter_set (void *counter_, int value_); |
| 589 | ZMQ_EXPORT int zmq_atomic_counter_inc (void *counter_); |
| 590 | ZMQ_EXPORT int zmq_atomic_counter_dec (void *counter_); |
| 591 | ZMQ_EXPORT int zmq_atomic_counter_value (void *counter_); |
| 592 | ZMQ_EXPORT void zmq_atomic_counter_destroy (void **counter_p_); |
| 593 | |
| 594 | /******************************************************************************/ |
| 595 | /* Scheduling timers */ |
| 596 | /******************************************************************************/ |
| 597 | |
| 598 | #define ZMQ_HAVE_TIMERS |
| 599 | |
| 600 | typedef void(zmq_timer_fn) (int timer_id, void *arg); |
| 601 | |
| 602 | ZMQ_EXPORT void *zmq_timers_new (void); |
| 603 | ZMQ_EXPORT int zmq_timers_destroy (void **timers_p); |
| 604 | ZMQ_EXPORT int |
| 605 | zmq_timers_add (void *timers, size_t interval, zmq_timer_fn handler, void *arg); |
| 606 | ZMQ_EXPORT int zmq_timers_cancel (void *timers, int timer_id); |
| 607 | ZMQ_EXPORT int |
| 608 | zmq_timers_set_interval (void *timers, int timer_id, size_t interval); |
| 609 | ZMQ_EXPORT int zmq_timers_reset (void *timers, int timer_id); |
| 610 | ZMQ_EXPORT long zmq_timers_timeout (void *timers); |
| 611 | ZMQ_EXPORT int zmq_timers_execute (void *timers); |
| 612 | |
| 613 | |
| 614 | /******************************************************************************/ |
| 615 | /* These functions are not documented by man pages -- use at your own risk. */ |
| 616 | /* If you need these to be part of the formal ZMQ API, then (a) write a man */ |
| 617 | /* page, and (b) write a test case in tests. */ |
| 618 | /******************************************************************************/ |
| 619 | |
| 620 | /* Helper functions are used by perf tests so that they don't have to care */ |
| 621 | /* about minutiae of time-related functions on different OS platforms. */ |
| 622 | |
| 623 | /* Starts the stopwatch. Returns the handle to the watch. */ |
| 624 | ZMQ_EXPORT void *zmq_stopwatch_start (void); |
| 625 | |
| 626 | /* Returns the number of microseconds elapsed since the stopwatch was */ |
| 627 | /* started, but does not stop or deallocate the stopwatch. */ |
| 628 | ZMQ_EXPORT unsigned long zmq_stopwatch_intermediate (void *watch_); |
| 629 | |
| 630 | /* Stops the stopwatch. Returns the number of microseconds elapsed since */ |
| 631 | /* the stopwatch was started, and deallocates that watch. */ |
| 632 | ZMQ_EXPORT unsigned long zmq_stopwatch_stop (void *watch_); |
| 633 | |
| 634 | /* Sleeps for specified number of seconds. */ |
| 635 | ZMQ_EXPORT void zmq_sleep (int seconds_); |
| 636 | |
| 637 | typedef void(zmq_thread_fn) (void *); |
| 638 | |
| 639 | /* Start a thread. Returns a handle to the thread. */ |
| 640 | ZMQ_EXPORT void *zmq_threadstart (zmq_thread_fn *func_, void *arg_); |
| 641 | |
| 642 | /* Wait for thread to complete then free up resources. */ |
| 643 | ZMQ_EXPORT void zmq_threadclose (void *thread_); |
| 644 | |
| 645 | |
| 646 | /******************************************************************************/ |
| 647 | /* These functions are DRAFT and disabled in stable releases, and subject to */ |
| 648 | /* change at ANY time until declared stable. */ |
| 649 | /******************************************************************************/ |
| 650 | |
| 651 | #ifdef ZMQ_BUILD_DRAFT_API |
| 652 | |
| 653 | /* DRAFT Socket types. */ |
| 654 | #define ZMQ_SERVER 12 |
| 655 | #define ZMQ_CLIENT 13 |
| 656 | #define ZMQ_RADIO 14 |
| 657 | #define ZMQ_DISH 15 |
| 658 | #define ZMQ_GATHER 16 |
| 659 | #define ZMQ_SCATTER 17 |
| 660 | #define ZMQ_DGRAM 18 |
| 661 | |
| 662 | /* DRAFT Socket options. */ |
| 663 | #define ZMQ_ZAP_ENFORCE_DOMAIN 93 |
| 664 | #define ZMQ_LOOPBACK_FASTPATH 94 |
| 665 | #define ZMQ_METADATA 95 |
| 666 | #define ZMQ_MULTICAST_LOOP 96 |
| 667 | #define ZMQ_ROUTER_NOTIFY 97 |
| 668 | #define ZMQ_XPUB_MANUAL_LAST_VALUE 98 |
| 669 | #define ZMQ_SOCKS_USERNAME 99 |
| 670 | #define ZMQ_SOCKS_PASSWORD 100 |
| 671 | #define ZMQ_IN_BATCH_SIZE 101 |
| 672 | #define ZMQ_OUT_BATCH_SIZE 102 |
| 673 | #define ZMQ_WSS_KEY_PEM 103 |
| 674 | #define ZMQ_WSS_CERT_PEM 104 |
| 675 | #define ZMQ_WSS_TRUST_PEM 105 |
| 676 | #define ZMQ_WSS_HOSTNAME 106 |
| 677 | #define ZMQ_WSS_TRUST_SYSTEM 107 |
| 678 | #define ZMQ_ONLY_FIRST_SUBSCRIBE 108 |
| 679 | |
| 680 | |
| 681 | /* DRAFT Context options */ |
| 682 | #define ZMQ_ZERO_COPY_RECV 10 |
| 683 | |
| 684 | /* DRAFT Context methods. */ |
| 685 | ZMQ_EXPORT int zmq_ctx_set_ext (void *context_, |
| 686 | int option_, |
| 687 | const void *optval_, |
| 688 | size_t optvallen_); |
| 689 | ZMQ_EXPORT int zmq_ctx_get_ext (void *context_, |
| 690 | int option_, |
| 691 | void *optval_, |
| 692 | size_t *optvallen_); |
| 693 | |
| 694 | /* DRAFT Socket methods. */ |
| 695 | ZMQ_EXPORT int zmq_join (void *s, const char *group); |
| 696 | ZMQ_EXPORT int zmq_leave (void *s, const char *group); |
| 697 | |
| 698 | /* DRAFT Msg methods. */ |
| 699 | ZMQ_EXPORT int zmq_msg_set_routing_id (zmq_msg_t *msg, uint32_t routing_id); |
| 700 | ZMQ_EXPORT uint32_t zmq_msg_routing_id (zmq_msg_t *msg); |
| 701 | ZMQ_EXPORT int zmq_msg_set_group (zmq_msg_t *msg, const char *group); |
| 702 | ZMQ_EXPORT const char *zmq_msg_group (zmq_msg_t *msg); |
| 703 | |
| 704 | /* DRAFT Msg property names. */ |
| 705 | #define ZMQ_MSG_PROPERTY_ROUTING_ID "Routing-Id" |
| 706 | #define ZMQ_MSG_PROPERTY_SOCKET_TYPE "Socket-Type" |
| 707 | #define ZMQ_MSG_PROPERTY_USER_ID "User-Id" |
| 708 | #define ZMQ_MSG_PROPERTY_PEER_ADDRESS "Peer-Address" |
| 709 | |
| 710 | /* Router notify options */ |
| 711 | #define ZMQ_NOTIFY_CONNECT 1 |
| 712 | #define ZMQ_NOTIFY_DISCONNECT 2 |
| 713 | |
| 714 | /******************************************************************************/ |
| 715 | /* Poller polling on sockets,fd and thread-safe sockets */ |
| 716 | /******************************************************************************/ |
| 717 | |
| 718 | #define ZMQ_HAVE_POLLER |
| 719 | |
| 720 | typedef struct zmq_poller_event_t |
| 721 | { |
| 722 | void *socket; |
| 723 | zmq_fd_t fd; |
| 724 | void *user_data; |
| 725 | short events; |
| 726 | } zmq_poller_event_t; |
| 727 | |
| 728 | ZMQ_EXPORT void *zmq_poller_new (void); |
| 729 | ZMQ_EXPORT int zmq_poller_destroy (void **poller_p); |
| 730 | ZMQ_EXPORT int |
| 731 | zmq_poller_add (void *poller, void *socket, void *user_data, short events); |
| 732 | ZMQ_EXPORT int zmq_poller_modify (void *poller, void *socket, short events); |
| 733 | ZMQ_EXPORT int zmq_poller_remove (void *poller, void *socket); |
| 734 | ZMQ_EXPORT int |
| 735 | zmq_poller_wait (void *poller, zmq_poller_event_t *event, long timeout); |
| 736 | ZMQ_EXPORT int zmq_poller_wait_all (void *poller, |
| 737 | zmq_poller_event_t *events, |
| 738 | int n_events, |
| 739 | long timeout); |
| 740 | ZMQ_EXPORT int zmq_poller_fd (void *poller, zmq_fd_t *fd); |
| 741 | |
| 742 | ZMQ_EXPORT int |
| 743 | zmq_poller_add_fd (void *poller, zmq_fd_t fd, void *user_data, short events); |
| 744 | ZMQ_EXPORT int zmq_poller_modify_fd (void *poller, zmq_fd_t fd, short events); |
| 745 | ZMQ_EXPORT int zmq_poller_remove_fd (void *poller, zmq_fd_t fd); |
| 746 | |
| 747 | ZMQ_EXPORT int zmq_socket_get_peer_state (void *socket, |
| 748 | const void *routing_id, |
| 749 | size_t routing_id_size); |
| 750 | |
| 751 | /* DRAFT Socket monitoring events */ |
| 752 | #define ZMQ_EVENT_PIPES_STATS 0x10000 |
| 753 | |
| 754 | #define ZMQ_CURRENT_EVENT_VERSION 1 |
| 755 | #define ZMQ_CURRENT_EVENT_VERSION_DRAFT 2 |
| 756 | |
| 757 | #define ZMQ_EVENT_ALL_V1 ZMQ_EVENT_ALL |
| 758 | #define ZMQ_EVENT_ALL_V2 ZMQ_EVENT_ALL_V1 | ZMQ_EVENT_PIPES_STATS |
| 759 | |
| 760 | ZMQ_EXPORT int zmq_socket_monitor_versioned ( |
| 761 | void *s_, const char *addr_, uint64_t events_, int event_version_, int type_); |
| 762 | ZMQ_EXPORT int zmq_socket_monitor_pipes_stats (void *s); |
| 763 | |
| 764 | #endif // ZMQ_BUILD_DRAFT_API |
| 765 | |
| 766 | |
| 767 | #undef ZMQ_EXPORT |
| 768 | |
| 769 | #ifdef __cplusplus |
| 770 | } |
| 771 | #endif |
| 772 | |
| 773 | #endif |
| 774 | |