zmq.h 29 KB

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