zmq.h 7.85 KB
Newer Older
Martin Sustrik's avatar
Martin Sustrik committed
1
/*
2 3
    Copyright (c) 2007-2011 iMatix Corporation
    Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
Martin Sustrik's avatar
Martin Sustrik committed
4 5 6 7

    This file is part of 0MQ.

    0MQ is free software; you can redistribute it and/or modify it under
8
    the terms of the GNU Lesser General Public License as published by
Martin Sustrik's avatar
Martin Sustrik committed
9 10 11 12 13 14
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    0MQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU Lesser General Public License for more details.
Martin Sustrik's avatar
Martin Sustrik committed
16

17
    You should have received a copy of the GNU Lesser General Public License
Martin Sustrik's avatar
Martin Sustrik committed
18 19 20
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

Martin Sustrik's avatar
Martin Sustrik committed
21 22
#ifndef __ZMQ_H_INCLUDED__
#define __ZMQ_H_INCLUDED__
Martin Sustrik's avatar
Martin Sustrik committed
23 24 25 26 27

#ifdef __cplusplus
extern "C" {
#endif

28
#include <errno.h>
Martin Sustrik's avatar
Martin Sustrik committed
29
#include <stddef.h>
30
#if defined _WIN32
31
#include <winsock2.h>
32
#endif
Martin Sustrik's avatar
Martin Sustrik committed
33

34
/*  Handle DSO symbol visibility                                             */
35 36 37 38 39 40
#if defined _WIN32
#   if defined DLL_EXPORT
#       define ZMQ_EXPORT __declspec(dllexport)
#   else
#       define ZMQ_EXPORT __declspec(dllimport)
#   endif
Martin Sustrik's avatar
Martin Sustrik committed
41
#else
42 43 44 45 46 47
#   if defined __SUNPRO_C  || defined __SUNPRO_CC
#       define ZMQ_EXPORT __global
#   elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER
#       define ZMQ_EXPORT __attribute__ ((visibility("default")))
#   else
#       define ZMQ_EXPORT
48
#   endif
Martin Sustrik's avatar
Martin Sustrik committed
49 50
#endif

51
/******************************************************************************/
52
/*  0MQ versioning support.                                                   */
53
/******************************************************************************/
54

55
/*  Version macros for compile-time API version detection                     */
56
#define ZMQ_VERSION_MAJOR 4
Martin Sustrik's avatar
Martin Sustrik committed
57
#define ZMQ_VERSION_MINOR 0
Martin Sustrik's avatar
Martin Sustrik committed
58
#define ZMQ_VERSION_PATCH 0
59 60 61 62 63 64 65

#define ZMQ_MAKE_VERSION(major, minor, patch) \
    ((major) * 10000 + (minor) * 100 + (patch))
#define ZMQ_VERSION \
    ZMQ_MAKE_VERSION(ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH)

/*  Run-time API version detection                                            */
66 67
ZMQ_EXPORT void zmq_version (int *major, int *minor, int *patch);

68
/******************************************************************************/
69
/*  0MQ errors.                                                               */
70
/******************************************************************************/
71

72
/*  A number random enough not to collide with different errno ranges on      */
73
/*  different OSes. The assumption is that error_t is at least 32-bit type.   */
74 75
#define ZMQ_HAUSNUMERO 156384712

76
/*  On Windows platform some of the standard POSIX errnos are not defined.    */
77 78 79 80 81 82
#ifndef ENOTSUP
#define ENOTSUP (ZMQ_HAUSNUMERO + 1)
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT (ZMQ_HAUSNUMERO + 2)
#endif
83 84 85 86 87 88 89 90 91 92 93 94
#ifndef ENOBUFS
#define ENOBUFS (ZMQ_HAUSNUMERO + 3)
#endif
#ifndef ENETDOWN
#define ENETDOWN (ZMQ_HAUSNUMERO + 4)
#endif
#ifndef EADDRINUSE
#define EADDRINUSE (ZMQ_HAUSNUMERO + 5)
#endif
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL (ZMQ_HAUSNUMERO + 6)
#endif
malosek's avatar
malosek committed
95 96 97
#ifndef ECONNREFUSED
#define ECONNREFUSED (ZMQ_HAUSNUMERO + 7)
#endif
98 99 100
#ifndef EINPROGRESS
#define EINPROGRESS (ZMQ_HAUSNUMERO + 8)
#endif
101 102 103
#ifndef ENOTSOCK
#define ENOTSOCK (ZMQ_HAUSNUMERO + 9)
#endif
104 105 106
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT (ZMQ_HAUSNUMERO + 10)
#endif
107

108
/*  Native 0MQ error codes.                                                   */
109 110
#define EFSM (ZMQ_HAUSNUMERO + 51)
#define ENOCOMPATPROTO (ZMQ_HAUSNUMERO + 52)
111
#define ETERM (ZMQ_HAUSNUMERO + 53)
112
#define EMTHREAD (ZMQ_HAUSNUMERO + 54)
113
#define ECANTROUTE (ZMQ_HAUSNUMERO + 55)
114

115 116 117 118
/*  This function retrieves the errno as it is known to 0MQ library. The goal */
/*  of this function is to make the code 100% portable, including where 0MQ   */
/*  compiled with certain CRT library (on Windows) is linked to an            */
/*  application that uses different CRT library.                              */
119
ZMQ_EXPORT int zmq_errno (void);
120 121

/*  Resolves system errors and 0MQ errors to human-readable string.           */
122 123
ZMQ_EXPORT const char *zmq_strerror (int errnum);

124 125 126
/******************************************************************************/
/*  0MQ message definition.                                                   */
/******************************************************************************/
127

128
typedef struct {unsigned char _ [32];} zmq_msg_t;
Martin Sustrik's avatar
Martin Sustrik committed
129

130
typedef void (zmq_free_fn) (void *data, void *hint);
Martin Sustrik's avatar
Martin Sustrik committed
131

132
ZMQ_EXPORT int zmq_msg_init (zmq_msg_t *msg);
133 134
ZMQ_EXPORT int zmq_msg_init_size (zmq_msg_t *msg, size_t size);
ZMQ_EXPORT int zmq_msg_init_data (zmq_msg_t *msg, void *data,
135
    size_t size, zmq_free_fn *ffn, void *hint);
136 137 138 139 140
ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg);
ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src);
ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src);
ZMQ_EXPORT void *zmq_msg_data (zmq_msg_t *msg);
ZMQ_EXPORT size_t zmq_msg_size (zmq_msg_t *msg);
Martin Sustrik's avatar
Martin Sustrik committed
141

142 143 144
/******************************************************************************/
/*  0MQ infrastructure (a.k.a. context) initialisation & termination.         */
/******************************************************************************/
145

146
ZMQ_EXPORT void *zmq_init (int io_threads);
Martin Sustrik's avatar
Martin Sustrik committed
147
ZMQ_EXPORT int zmq_term (void *context);
Martin Sustrik's avatar
Martin Sustrik committed
148

149 150 151
/******************************************************************************/
/*  0MQ socket definition.                                                    */
/******************************************************************************/
152

Martin Sustrik's avatar
Martin Sustrik committed
153
/*  Socket types.                                                             */ 
154 155 156 157 158 159 160 161 162
#define ZMQ_PAIR 0
#define ZMQ_PUB 1
#define ZMQ_SUB 2
#define ZMQ_REQ 3
#define ZMQ_REP 4
#define ZMQ_XREQ 5
#define ZMQ_XREP 6
#define ZMQ_PULL 7
#define ZMQ_PUSH 8
163 164
#define ZMQ_XPUB 9
#define ZMQ_XSUB 10
165
#define ZMQ_ROUTER 13
166

167
/*  Socket options.                                                           */
168 169 170 171
#define ZMQ_AFFINITY 4
#define ZMQ_SUBSCRIBE 6
#define ZMQ_UNSUBSCRIBE 7
#define ZMQ_RATE 8
172
#define ZMQ_RECOVERY_IVL 9
173 174 175 176 177
#define ZMQ_SNDBUF 11
#define ZMQ_RCVBUF 12
#define ZMQ_RCVMORE 13
#define ZMQ_FD 14
#define ZMQ_EVENTS 15
178
#define ZMQ_TYPE 16
179
#define ZMQ_LINGER 17
180
#define ZMQ_RECONNECT_IVL 18
181
#define ZMQ_BACKLOG 19
182
#define ZMQ_RECONNECT_IVL_MAX 21
183
#define ZMQ_MAXMSGSIZE 22
184 185
#define ZMQ_SNDHWM 23
#define ZMQ_RCVHWM 24
186
#define ZMQ_MULTICAST_HOPS 25
187 188
#define ZMQ_RCVTIMEO 27
#define ZMQ_SNDTIMEO 28
189
#define ZMQ_RCVLABEL 29
190
#define ZMQ_RCVCMD 30
Steven McCoy's avatar
Steven McCoy committed
191 192
#define ZMQ_IPV4ONLY 31

193
/*  Send/recv options.                                                        */
194
#define ZMQ_DONTWAIT 1
195
#define ZMQ_SNDMORE 2
196
#define ZMQ_SNDLABEL 4
197
#define ZMQ_SNDCMD 8
198 199 200

ZMQ_EXPORT void *zmq_socket (void *context, int type);
ZMQ_EXPORT int zmq_close (void *s);
201 202
ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval,
    size_t optvallen); 
203 204
ZMQ_EXPORT int zmq_getsockopt (void *s, int option, void *optval,
    size_t *optvallen);
205 206
ZMQ_EXPORT int zmq_bind (void *s, const char *addr);
ZMQ_EXPORT int zmq_connect (void *s, const char *addr);
207 208 209 210
ZMQ_EXPORT int zmq_send (void *s, const void *buf, size_t len, int flags);
ZMQ_EXPORT int zmq_recv (void *s, void *buf, size_t len, int flags);
ZMQ_EXPORT int zmq_sendmsg (void *s, zmq_msg_t *msg, int flags);
ZMQ_EXPORT int zmq_recvmsg (void *s, zmq_msg_t *msg, int flags);
Martin Sustrik's avatar
Martin Sustrik committed
211

212 213 214
/******************************************************************************/
/*  I/O multiplexing.                                                         */
/******************************************************************************/
215

216 217 218
#define ZMQ_POLLIN 1
#define ZMQ_POLLOUT 2
#define ZMQ_POLLERR 4
219 220 221 222

typedef struct
{
    void *socket;
223 224 225
#if defined _WIN32
    SOCKET fd;
#else
226
    int fd;
227
#endif
228 229 230 231
    short events;
    short revents;
} zmq_pollitem_t;

232
ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout);
233

234 235
#undef ZMQ_EXPORT

Martin Sustrik's avatar
Martin Sustrik committed
236 237 238 239 240
#ifdef __cplusplus
}
#endif

#endif
241