![]() |
libzmq master
The Intelligent Transport Layer
|
00001 /* 00002 Copyright (c) 2009-2011 250bpm s.r.o. 00003 Copyright (c) 2007-2010 iMatix Corporation 00004 Copyright (c) 2011 VMware, Inc. 00005 Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file 00006 00007 This file is part of 0MQ. 00008 00009 0MQ is free software; you can redistribute it and/or modify it under 00010 the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation; either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 0MQ is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 00023 #ifndef __ZMQ_H_INCLUDED__ 00024 #define __ZMQ_H_INCLUDED__ 00025 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif 00029 00030 #include <errno.h> 00031 #include <stddef.h> 00032 #if defined _WIN32 00033 #include <winsock2.h> 00034 #endif 00035 00036 /* Handle DSO symbol visibility */ 00037 #if defined _WIN32 00038 # if defined DLL_EXPORT 00039 # define ZMQ_EXPORT __declspec(dllexport) 00040 # else 00041 # define ZMQ_EXPORT __declspec(dllimport) 00042 # endif 00043 #else 00044 # if defined __SUNPRO_C || defined __SUNPRO_CC 00045 # define ZMQ_EXPORT __global 00046 # elif (defined __GNUC__ && __GNUC__ >= 4) || defined __INTEL_COMPILER 00047 # define ZMQ_EXPORT __attribute__ ((visibility("default"))) 00048 # else 00049 # define ZMQ_EXPORT 00050 # endif 00051 #endif 00052 00053 /******************************************************************************/ 00054 /* 0MQ versioning support. */ 00055 /******************************************************************************/ 00056 00057 /* Version macros for compile-time API version detection */ 00058 #define ZMQ_VERSION_MAJOR 3 00059 #define ZMQ_VERSION_MINOR 1 00060 #define ZMQ_VERSION_PATCH 0 00061 00062 #define ZMQ_MAKE_VERSION(major, minor, patch) \ 00063 ((major) * 10000 + (minor) * 100 + (patch)) 00064 #define ZMQ_VERSION \ 00065 ZMQ_MAKE_VERSION(ZMQ_VERSION_MAJOR, ZMQ_VERSION_MINOR, ZMQ_VERSION_PATCH) 00066 00067 /* Run-time API version detection */ 00068 ZMQ_EXPORT void zmq_version (int *major, int *minor, int *patch); 00069 00070 /******************************************************************************/ 00071 /* 0MQ errors. */ 00072 /******************************************************************************/ 00073 00074 /* A number random enough not to collide with different errno ranges on */ 00075 /* different OSes. The assumption is that error_t is at least 32-bit type. */ 00076 #define ZMQ_HAUSNUMERO 156384712 00077 00078 /* On Windows platform some of the standard POSIX errnos are not defined. */ 00079 #ifndef ENOTSUP 00080 #define ENOTSUP (ZMQ_HAUSNUMERO + 1) 00081 #endif 00082 #ifndef EPROTONOSUPPORT 00083 #define EPROTONOSUPPORT (ZMQ_HAUSNUMERO + 2) 00084 #endif 00085 #ifndef ENOBUFS 00086 #define ENOBUFS (ZMQ_HAUSNUMERO + 3) 00087 #endif 00088 #ifndef ENETDOWN 00089 #define ENETDOWN (ZMQ_HAUSNUMERO + 4) 00090 #endif 00091 #ifndef EADDRINUSE 00092 #define EADDRINUSE (ZMQ_HAUSNUMERO + 5) 00093 #endif 00094 #ifndef EADDRNOTAVAIL 00095 #define EADDRNOTAVAIL (ZMQ_HAUSNUMERO + 6) 00096 #endif 00097 #ifndef ECONNREFUSED 00098 #define ECONNREFUSED (ZMQ_HAUSNUMERO + 7) 00099 #endif 00100 #ifndef EINPROGRESS 00101 #define EINPROGRESS (ZMQ_HAUSNUMERO + 8) 00102 #endif 00103 #ifndef ENOTSOCK 00104 #define ENOTSOCK (ZMQ_HAUSNUMERO + 9) 00105 #endif 00106 #ifndef EAFNOSUPPORT 00107 #define EAFNOSUPPORT (ZMQ_HAUSNUMERO + 10) 00108 #endif 00109 00110 /* Native 0MQ error codes. */ 00111 #define EFSM (ZMQ_HAUSNUMERO + 51) 00112 #define ENOCOMPATPROTO (ZMQ_HAUSNUMERO + 52) 00113 #define ETERM (ZMQ_HAUSNUMERO + 53) 00114 #define EMTHREAD (ZMQ_HAUSNUMERO + 54) 00115 00116 /* This function retrieves the errno as it is known to 0MQ library. The goal */ 00117 /* of this function is to make the code 100% portable, including where 0MQ */ 00118 /* compiled with certain CRT library (on Windows) is linked to an */ 00119 /* application that uses different CRT library. */ 00120 ZMQ_EXPORT int zmq_errno (void); 00121 00122 /* Resolves system errors and 0MQ errors to human-readable string. */ 00123 ZMQ_EXPORT const char *zmq_strerror (int errnum); 00124 00125 /******************************************************************************/ 00126 /* 0MQ message definition. */ 00127 /******************************************************************************/ 00128 00129 typedef struct {unsigned char _ [32];} zmq_msg_t; 00130 00131 typedef void (zmq_free_fn) (void *data, void *hint); 00132 00133 ZMQ_EXPORT int zmq_msg_init (zmq_msg_t *msg); 00134 ZMQ_EXPORT int zmq_msg_init_size (zmq_msg_t *msg, size_t size); 00135 ZMQ_EXPORT int zmq_msg_init_data (zmq_msg_t *msg, void *data, 00136 size_t size, zmq_free_fn *ffn, void *hint); 00137 ZMQ_EXPORT int zmq_msg_close (zmq_msg_t *msg); 00138 ZMQ_EXPORT int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src); 00139 ZMQ_EXPORT int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src); 00140 ZMQ_EXPORT void *zmq_msg_data (zmq_msg_t *msg); 00141 ZMQ_EXPORT size_t zmq_msg_size (zmq_msg_t *msg); 00142 ZMQ_EXPORT int zmq_getmsgopt (zmq_msg_t *msg, int option, void *optval, 00143 size_t *optvallen); 00144 00145 /******************************************************************************/ 00146 /* 0MQ infrastructure (a.k.a. context) initialisation & termination. */ 00147 /******************************************************************************/ 00148 00149 ZMQ_EXPORT void *zmq_init (int io_threads); 00150 ZMQ_EXPORT int zmq_term (void *context); 00151 00152 /******************************************************************************/ 00153 /* 0MQ socket definition. */ 00154 /******************************************************************************/ 00155 00156 /* Socket types. */ 00157 #define ZMQ_PAIR 0 00158 #define ZMQ_PUB 1 00159 #define ZMQ_SUB 2 00160 #define ZMQ_REQ 3 00161 #define ZMQ_REP 4 00162 #define ZMQ_XREQ 5 00163 #define ZMQ_XREP 6 00164 #define ZMQ_PULL 7 00165 #define ZMQ_PUSH 8 00166 #define ZMQ_XPUB 9 00167 #define ZMQ_XSUB 10 00168 00169 #define ZMQ_ROUTER ZMQ_XREP 00170 #define ZMQ_DEALER ZMQ_XREQ 00171 00172 /* Socket options. */ 00173 #define ZMQ_AFFINITY 4 00174 #define ZMQ_IDENTITY 5 00175 #define ZMQ_SUBSCRIBE 6 00176 #define ZMQ_UNSUBSCRIBE 7 00177 #define ZMQ_RATE 8 00178 #define ZMQ_RECOVERY_IVL 9 00179 #define ZMQ_SNDBUF 11 00180 #define ZMQ_RCVBUF 12 00181 #define ZMQ_RCVMORE 13 00182 #define ZMQ_FD 14 00183 #define ZMQ_EVENTS 15 00184 #define ZMQ_TYPE 16 00185 #define ZMQ_LINGER 17 00186 #define ZMQ_RECONNECT_IVL 18 00187 #define ZMQ_BACKLOG 19 00188 #define ZMQ_RECONNECT_IVL_MAX 21 00189 #define ZMQ_MAXMSGSIZE 22 00190 #define ZMQ_SNDHWM 23 00191 #define ZMQ_RCVHWM 24 00192 #define ZMQ_MULTICAST_HOPS 25 00193 #define ZMQ_RCVTIMEO 27 00194 #define ZMQ_SNDTIMEO 28 00195 #define ZMQ_IPV4ONLY 31 00196 00197 /* Message options */ 00198 #define ZMQ_MORE 1 00199 00200 /* Send/recv options. */ 00201 #define ZMQ_DONTWAIT 1 00202 #define ZMQ_SNDMORE 2 00203 00204 ZMQ_EXPORT void *zmq_socket (void *context, int type); 00205 ZMQ_EXPORT int zmq_close (void *s); 00206 ZMQ_EXPORT int zmq_setsockopt (void *s, int option, const void *optval, 00207 size_t optvallen); 00208 ZMQ_EXPORT int zmq_getsockopt (void *s, int option, void *optval, 00209 size_t *optvallen); 00210 ZMQ_EXPORT int zmq_bind (void *s, const char *addr); 00211 ZMQ_EXPORT int zmq_connect (void *s, const char *addr); 00212 ZMQ_EXPORT int zmq_send (void *s, const void *buf, size_t len, int flags); 00213 ZMQ_EXPORT int zmq_recv (void *s, void *buf, size_t len, int flags); 00214 ZMQ_EXPORT int zmq_sendmsg (void *s, zmq_msg_t *msg, int flags); 00215 ZMQ_EXPORT int zmq_recvmsg (void *s, zmq_msg_t *msg, int flags); 00216 00217 /******************************************************************************/ 00218 /* I/O multiplexing. */ 00219 /******************************************************************************/ 00220 00221 #define ZMQ_POLLIN 1 00222 #define ZMQ_POLLOUT 2 00223 #define ZMQ_POLLERR 4 00224 00225 typedef struct 00226 { 00227 void *socket; 00228 #if defined _WIN32 00229 SOCKET fd; 00230 #else 00231 int fd; 00232 #endif 00233 short events; 00234 short revents; 00235 } zmq_pollitem_t; 00236 00237 ZMQ_EXPORT int zmq_poll (zmq_pollitem_t *items, int nitems, long timeout); 00238 00239 #undef ZMQ_EXPORT 00240 00241 #ifdef __cplusplus 00242 } 00243 #endif 00244 00245 #endif 00246