Mercurial > hg > fxanalyse
comparison zmq.h @ 241:65ab87e5a8d6
Add ZMQ library
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Thu, 12 Feb 2015 22:43:46 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
240:7fd5cb857d07 | 241:65ab87e5a8d6 |
---|---|
1 /* | |
2 Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file | |
3 | |
4 This file is part of 0MQ. | |
5 | |
6 0MQ is free software; you can redistribute it and/or modify it under | |
7 the terms of the GNU Lesser General Public License as published by | |
8 the Free Software Foundation; either version 3 of the License, or | |
9 (at your option) any later version. | |
10 | |
11 0MQ is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU Lesser General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU Lesser General Public License | |
17 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 ************************************************************************* | |
20 NOTE to contributors. This file comprises the principal public contract | |
21 for ZeroMQ API users (along with zmq_utils.h). Any change to this file | |
22 supplied in a stable release SHOULD not break existing applications. | |
23 In practice this means that the value of constants must not change, and | |
24 that old values may not be reused for new constants. | |
25 ************************************************************************* | |
26 */ | |
27 | |
28 #ifndef __ZMQ_H_INCLUDED__ | |
29 #define __ZMQ_H_INCLUDED__ | |
30 | |
31 /* Version macros for compile-time API version detection */ | |
32 #define ZMQ_VERSION_MAJOR 4 | |
33 #define ZMQ_VERSION_MINOR 0 | |
34 #define ZMQ_VERSION_PATCH 4 | |
35 | |
36 #define ZMQ_MAKE_VERSION(major, minor, patch) \ | |
37 ((major) * 10000 + (minor) * 100 + (patch)) | |
38 #define ZMQ_VERSION \ | |
39 ZMQ_MAKE_VERSION(ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH) | |
40 | |
41 #ifdef __cplusplus | |
42 extern "C" { | |
43 #endif | |
44 | |
45 #if !defined _WIN32_WCE | |
46 #include <errno.h> | |
47 #endif | |
48 #include <stddef.h> | |
49 #include <stdio.h> | |
50 #if defined _WIN32 | |
51 #include <winsock2.h> | |
52 #endif | |
53 | |
54 /* Handle DSO symbol visibility */ | |
55 #if defined _WIN32 | |
56 # if defined ZMQ_STATIC | |
57 # define ZMQ_EXPORT | |
58 # elif defined DLL_EXPORT | |
59 # define ZMQ_EXPORT __declspec(dllexport) | |
60 # else | |
61 # define ZMQ_EXPORT __declspec(dllimport) | |
62 # endif | |
63 #else | |
64 # if defined __SUNPRO_C || defined __SUNPRO_CC | |
65 # define ZMQ_EXPORT __global | |
66 # elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER | |
67 # define ZMQ_EXPORT __attribute__ ((visibility("default"))) | |
68 # else | |
69 # define ZMQ_EXPORT | |
70 # endif | |
71 #endif | |
72 | |
73 /* Define integer types needed for event interface */ | |
74 #if defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_OPENVMS | |
75 # include <inttypes.h> | |
76 #elif defined _MSC_VER && _MSC_VER < 1600 | |
77 # ifndef int32_t | |
78 typedef __int32 int32_t; | |
79 # endif | |
80 # ifndef uint16_t | |
81 typedef unsigned __int16 uint16_t; | |
82 # endif | |
83 # ifndef uint8_t | |
84 typedef unsigned __int8 uint8_t; | |
85 # endif | |
86 #else | |
87 # include <stdint.h> | |
88 #endif | |
89 | |
90 | |
91 /******************************************************************************/ | |
92 /* 0MQ errors. */ | |
93 /******************************************************************************/ | |
94 | |
95 /* A number random enough not to collide with different errno ranges on */ | |
96 /* different OSes. The assumption is that error_t is at least 32-bit type. */ | |
97 #define ZMQ_HAUSNUMERO 156384712 | |
98 | |
99 /* On Windows platform some of the standard POSIX errnos are not defined. */ | |
100 #ifndef ENOTSUP | |
101 #define ENOTSUP (ZMQ_HAUSNUMERO + 1) | |
102 #endif | |
103 #ifndef EPROTONOSUPPORT | |
104 #define EPROTONOSUPPORT (ZMQ_HAUSNUMERO + 2) | |
105 #endif | |
106 #ifndef ENOBUFS | |
107 #define ENOBUFS (ZMQ_HAUSNUMERO + 3) | |
108 #endif | |
109 #ifndef ENETDOWN | |
110 #define ENETDOWN (ZMQ_HAUSNUMERO + 4) | |
111 #endif | |
112 #ifndef EADDRINUSE | |
113 #define EADDRINUSE (ZMQ_HAUSNUMERO + 5) | |
114 #endif | |
115 #ifndef EADDRNOTAVAIL | |
116 #define EADDRNOTAVAIL (ZMQ_HAUSNUMERO + 6) | |
117 #endif | |
118 #ifndef ECONNREFUSED | |
119 #define ECONNREFUSED (ZMQ_HAUSNUMERO + 7) | |
120 #endif | |
121 #ifndef EINPROGRESS | |
122 #define EINPROGRESS (ZMQ_HAUSNUMERO + 8) | |
123 #endif | |
124 #ifndef ENOTSOCK | |
125 #define ENOTSOCK (ZMQ_HAUSNUMERO + 9) | |
126 #endif | |
127 #ifndef EMSGSIZE | |
128 #define EMSGSIZE (ZMQ_HAUSNUMERO + 10) | |
129 #endif | |
130 #ifndef EAFNOSUPPORT | |
131 #define EAFNOSUPPORT (ZMQ_HAUSNUMERO + 11) | |
132 #endif | |
133 #ifndef ENETUNREACH | |
134 #define ENETUNREACH (ZMQ_HAUSNUMERO + 12) | |
135 #endif | |
136 #ifndef ECONNABORTED | |
137 #define ECONNABORTED (ZMQ_HAUSNUMERO + 13) | |
138 #endif | |
139 #ifndef ECONNRESET | |
140 #define ECONNRESET (ZMQ_HAUSNUMERO + 14) | |
141 #endif | |
142 #ifndef ENOTCONN | |
143 #define ENOTCONN (ZMQ_HAUSNUMERO + 15) | |
144 #endif | |
145 #ifndef ETIMEDOUT | |
146 #define ETIMEDOUT (ZMQ_HAUSNUMERO + 16) | |
147 #endif | |
148 #ifndef EHOSTUNREACH | |
149 #define EHOSTUNREACH (ZMQ_HAUSNUMERO + 17) | |
150 #endif | |
151 #ifndef ENETRESET | |
152 #define ENETRESET (ZMQ_HAUSNUMERO + 18) | |
153 #endif | |
154 | |
155 /* Native 0MQ error codes. */ | |
156 #define EFSM (ZMQ_HAUSNUMERO + 51) | |
157 #define ENOCOMPATPROTO (ZMQ_HAUSNUMERO + 52) | |
158 #define ETERM (ZMQ_HAUSNUMERO + 53) | |
159 #define EMTHREAD (ZMQ_HAUSNUMERO + 54) | |
160 | |
161 /* Run-time API version detection */ | |
162 ZMQ_EXPORT void zmq_version (int *major, int *minor, int *patch); | |
163 | |
164 /* This function retrieves the errno as it is known to 0MQ library. The goal */ | |
165 /* of this function is to make the code 100% portable, including where 0MQ */ | |
166 /* compiled with certain CRT library (on Windows) is linked to an */ | |
167 /* application that uses different CRT library. */ | |
168 ZMQ_EXPORT int zmq_errno (void); | |
169 | |
170 /* Resolves system errors and 0MQ errors to human-readable string. */ | |
171 ZMQ_EXPORT const char *zmq_strerror (int errnum); | |
172 | |
173 /******************************************************************************/ | |
174 /* 0MQ infrastructure (a.k.a. context) initialisation & termination. */ | |
175 /******************************************************************************/ | |
176 | |
177 /* New API */ | |
178 /* Context options */ | |
179 #define ZMQ_IO_THREADS 1 | |
180 #define ZMQ_MAX_SOCKETS 2 | |
181 | |
182 /* Default for new contexts */ | |
183 #define ZMQ_IO_THREADS_DFLT 1 | |
184 #define ZMQ_MAX_SOCKETS_DFLT 1023 | |
185 | |
186 ZMQ_EXPORT void *zmq_ctx_new (void); | |
187 ZMQ_EXPORT int zmq_ctx_term (void *context); | |
188 ZMQ_EXPORT int zmq_ctx_shutdown (void *ctx_); | |
189 ZMQ_EXPORT int zmq_ctx_set (void *context, int option, int optval); | |
190 ZMQ_EXPORT int zmq_ctx_get (void *context, int option); | |
191 | |
192 /* Old (legacy) API */ | |
193 ZMQ_EXPORT void *zmq_init (int io_threads); | |
194 ZMQ_EXPORT int zmq_term (void *context); | |
195 ZMQ_EXPORT int zmq_ctx_destroy (void *context); | |
196 | |
197 | |
198 /******************************************************************************/ | |
199 /* 0MQ message definition. */ | |
200 /******************************************************************************/ | |
201 | |
202 typedef struct zmq_msg_t {unsigned char _ [32];} zmq_msg_t; | |
203 | |
204 typedef void (zmq_free_fn) (void *data, void *hint); | |
205 | |
206 ZMQ_EXPORT int zmq_msg_init (zmq_msg_t *msg); | |
207 ZMQ_EXPORT int zmq_msg_init_size (zmq_msg_t *msg, size_t size); | |
208 ZMQ_EXPORT int zmq_msg_init_data (zmq_msg_t *msg, void *data, | |
209 size_t size, zmq_free_fn *ffn, void *hint); | |
210 ZMQ_EXPORT int zmq_msg_send (zmq_msg_t *msg, void *s, int flags); | |
211 ZMQ_EXPORT int zmq_msg_recv (zmq_msg_t *msg, void *s, int flags); | |
212 ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg); | |
213 ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src); | |
214 ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src); | |
215 ZMQ_EXPORT void *zmq_msg_data (zmq_msg_t *msg); | |
216 ZMQ_EXPORT size_t zmq_msg_size (zmq_msg_t *msg); | |
217 ZMQ_EXPORT int zmq_msg_more (zmq_msg_t *msg); | |
218 ZMQ_EXPORT int zmq_msg_get (zmq_msg_t *msg, int option); | |
219 ZMQ_EXPORT int zmq_msg_set (zmq_msg_t *msg, int option, int optval); | |
220 | |
221 | |
222 /******************************************************************************/ | |
223 /* 0MQ socket definition. */ | |
224 /******************************************************************************/ | |
225 | |
226 /* Socket types. */ | |
227 #define ZMQ_PAIR 0 | |
228 #define ZMQ_PUB 1 | |
229 #define ZMQ_SUB 2 | |
230 #define ZMQ_REQ 3 | |
231 #define ZMQ_REP 4 | |
232 #define ZMQ_DEALER 5 | |
233 #define ZMQ_ROUTER 6 | |
234 #define ZMQ_PULL 7 | |
235 #define ZMQ_PUSH 8 | |
236 #define ZMQ_XPUB 9 | |
237 #define ZMQ_XSUB 10 | |
238 #define ZMQ_STREAM 11 | |
239 | |
240 /* Deprecated aliases */ | |
241 #define ZMQ_XREQ ZMQ_DEALER | |
242 #define ZMQ_XREP ZMQ_ROUTER | |
243 | |
244 /* Socket options. */ | |
245 #define ZMQ_AFFINITY 4 | |
246 #define ZMQ_IDENTITY 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_TCP_ACCEPT_FILTER 38 | |
274 #define ZMQ_IMMEDIATE 39 | |
275 #define ZMQ_XPUB_VERBOSE 40 | |
276 #define ZMQ_ROUTER_RAW 41 | |
277 #define ZMQ_IPV6 42 | |
278 #define ZMQ_MECHANISM 43 | |
279 #define ZMQ_PLAIN_SERVER 44 | |
280 #define ZMQ_PLAIN_USERNAME 45 | |
281 #define ZMQ_PLAIN_PASSWORD 46 | |
282 #define ZMQ_CURVE_SERVER 47 | |
283 #define ZMQ_CURVE_PUBLICKEY 48 | |
284 #define ZMQ_CURVE_SECRETKEY 49 | |
285 #define ZMQ_CURVE_SERVERKEY 50 | |
286 #define ZMQ_PROBE_ROUTER 51 | |
287 #define ZMQ_REQ_CORRELATE 52 | |
288 #define ZMQ_REQ_RELAXED 53 | |
289 #define ZMQ_CONFLATE 54 | |
290 #define ZMQ_ZAP_DOMAIN 55 | |
291 | |
292 /* Message options */ | |
293 #define ZMQ_MORE 1 | |
294 | |
295 /* Send/recv options. */ | |
296 #define ZMQ_DONTWAIT 1 | |
297 #define ZMQ_SNDMORE 2 | |
298 | |
299 /* Security mechanisms */ | |
300 #define ZMQ_NULL 0 | |
301 #define ZMQ_PLAIN 1 | |
302 #define ZMQ_CURVE 2 | |
303 | |
304 /* Deprecated options and aliases */ | |
305 #define ZMQ_IPV4ONLY 31 | |
306 #define ZMQ_DELAY_ATTACH_ON_CONNECT ZMQ_IMMEDIATE | |
307 #define ZMQ_NOBLOCK ZMQ_DONTWAIT | |
308 #define ZMQ_FAIL_UNROUTABLE ZMQ_ROUTER_MANDATORY | |
309 #define ZMQ_ROUTER_BEHAVIOR ZMQ_ROUTER_MANDATORY | |
310 | |
311 /******************************************************************************/ | |
312 /* 0MQ socket events and monitoring */ | |
313 /******************************************************************************/ | |
314 | |
315 /* Socket transport events (tcp and ipc only) */ | |
316 #define ZMQ_EVENT_CONNECTED 1 | |
317 #define ZMQ_EVENT_CONNECT_DELAYED 2 | |
318 #define ZMQ_EVENT_CONNECT_RETRIED 4 | |
319 | |
320 #define ZMQ_EVENT_LISTENING 8 | |
321 #define ZMQ_EVENT_BIND_FAILED 16 | |
322 | |
323 #define ZMQ_EVENT_ACCEPTED 32 | |
324 #define ZMQ_EVENT_ACCEPT_FAILED 64 | |
325 | |
326 #define ZMQ_EVENT_CLOSED 128 | |
327 #define ZMQ_EVENT_CLOSE_FAILED 256 | |
328 #define ZMQ_EVENT_DISCONNECTED 512 | |
329 #define ZMQ_EVENT_MONITOR_STOPPED 1024 | |
330 | |
331 #define ZMQ_EVENT_ALL ( ZMQ_EVENT_CONNECTED | ZMQ_EVENT_CONNECT_DELAYED | \ | |
332 ZMQ_EVENT_CONNECT_RETRIED | ZMQ_EVENT_LISTENING | \ | |
333 ZMQ_EVENT_BIND_FAILED | ZMQ_EVENT_ACCEPTED | \ | |
334 ZMQ_EVENT_ACCEPT_FAILED | ZMQ_EVENT_CLOSED | \ | |
335 ZMQ_EVENT_CLOSE_FAILED | ZMQ_EVENT_DISCONNECTED | \ | |
336 ZMQ_EVENT_MONITOR_STOPPED) | |
337 | |
338 /* Socket event data */ | |
339 typedef struct { | |
340 uint16_t event; // id of the event as bitfield | |
341 int32_t value ; // value is either error code, fd or reconnect interval | |
342 } zmq_event_t; | |
343 | |
344 ZMQ_EXPORT void *zmq_socket (void *, int type); | |
345 ZMQ_EXPORT int zmq_close (void *s); | |
346 ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval, | |
347 size_t optvallen); | |
348 ZMQ_EXPORT int zmq_getsockopt (void *s, int option, void *optval, | |
349 size_t *optvallen); | |
350 ZMQ_EXPORT int zmq_bind (void *s, const char *addr); | |
351 ZMQ_EXPORT int zmq_connect (void *s, const char *addr); | |
352 ZMQ_EXPORT int zmq_unbind (void *s, const char *addr); | |
353 ZMQ_EXPORT int zmq_disconnect (void *s, const char *addr); | |
354 ZMQ_EXPORT int zmq_send (void *s, const void *buf, size_t len, int flags); | |
355 ZMQ_EXPORT int zmq_send_const (void *s, const void *buf, size_t len, int flags); | |
356 ZMQ_EXPORT int zmq_recv (void *s, void *buf, size_t len, int flags); | |
357 ZMQ_EXPORT int zmq_socket_monitor (void *s, const char *addr, int events); | |
358 | |
359 ZMQ_EXPORT int zmq_sendmsg (void *s, zmq_msg_t *msg, int flags); | |
360 ZMQ_EXPORT int zmq_recvmsg (void *s, zmq_msg_t *msg, int flags); | |
361 | |
362 /* Experimental */ | |
363 struct iovec; | |
364 | |
365 ZMQ_EXPORT int zmq_sendiov (void *s, struct iovec *iov, size_t count, int flags); | |
366 ZMQ_EXPORT int zmq_recviov (void *s, struct iovec *iov, size_t *count, int flags); | |
367 | |
368 /******************************************************************************/ | |
369 /* I/O multiplexing. */ | |
370 /******************************************************************************/ | |
371 | |
372 #define ZMQ_POLLIN 1 | |
373 #define ZMQ_POLLOUT 2 | |
374 #define ZMQ_POLLERR 4 | |
375 | |
376 typedef struct | |
377 { | |
378 void *socket; | |
379 #if defined _WIN32 | |
380 SOCKET fd; | |
381 #else | |
382 int fd; | |
383 #endif | |
384 short events; | |
385 short revents; | |
386 } zmq_pollitem_t; | |
387 | |
388 #define ZMQ_POLLITEMS_DFLT 16 | |
389 | |
390 ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout); | |
391 | |
392 /* Built-in message proxy (3-way) */ | |
393 | |
394 ZMQ_EXPORT int zmq_proxy (void *frontend, void *backend, void *capture); | |
395 | |
396 /* Encode a binary key as printable text using ZMQ RFC 32 */ | |
397 ZMQ_EXPORT char *zmq_z85_encode (char *dest, uint8_t *data, size_t size); | |
398 | |
399 /* Encode a binary key from printable text per ZMQ RFC 32 */ | |
400 ZMQ_EXPORT uint8_t *zmq_z85_decode (uint8_t *dest, char *string); | |
401 | |
402 /* Deprecated aliases */ | |
403 #define ZMQ_STREAMER 1 | |
404 #define ZMQ_FORWARDER 2 | |
405 #define ZMQ_QUEUE 3 | |
406 /* Deprecated method */ | |
407 ZMQ_EXPORT int zmq_device (int type, void *frontend, void *backend); | |
408 | |
409 #undef ZMQ_EXPORT | |
410 | |
411 #ifdef __cplusplus | |
412 } | |
413 #endif | |
414 | |
415 #endif | |
416 |