zmq.h 30 KB

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