Zth (libzth)
zmq.h
Go to the documentation of this file.
1 #ifndef ZTH_ZMQ_H
2 #define ZTH_ZMQ_H
3 /*
4  * Zth (libzth), a cooperative userspace multitasking library.
5  * Copyright (C) 2019-2022 Jochem Rutgers
6  *
7  * This Source Code Form is subject to the terms of the Mozilla Public
8  * License, v. 2.0. If a copy of the MPL was not distributed with this
9  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
10  */
11 
21 #include <libzth/macros.h>
22 
23 #ifdef ZTH_HAVE_LIBZMQ
24 # include <zmq.h>
25 
26 # ifndef ZTH_REDIRECT_ZMQ
27 # define ZTH_REDIRECT_ZMQ 1
28 # endif
29 
30 # ifdef __cplusplus
31 namespace zth {
32 namespace zmq {
33 
34 void* zmq_context();
35 void* zmq_socket(int type);
36 int zmq_msg_send(zmq_msg_t* msg, void* socket, int flags);
37 int zmq_msg_recv(zmq_msg_t* msg, void* socket, int flags);
38 int zmq_send(void* socket, void const* buf, size_t len, int flags);
39 int zmq_recv(void* socket, void* buf, size_t len, int flags);
40 int zmq_send_const(void* socket, void const* buf, size_t len, int flags);
41 
42 } // namespace zmq
43 } // namespace zth
44 
45 # endif // __cplusplus
46 
47 # if ZTH_REDIRECT_ZMQ
48 # ifdef __cplusplus
54 EXTERN_C ZTH_EXPORT ZTH_INLINE void* zth_zmq_context()
55 {
56  return zth::zmq::zmq_context();
57 }
58 
64 EXTERN_C ZTH_EXPORT ZTH_INLINE void* zth_zmq_socket(int type)
65 {
66  return zth::zmq::zmq_socket(type);
67 }
68 
74 EXTERN_C ZTH_EXPORT ZTH_INLINE int zth_zmq_msg_send(zmq_msg_t* msg, void* socket, int flags)
75 {
76  return zth::zmq::zmq_msg_send(msg, socket, flags);
77 }
78 
84 EXTERN_C ZTH_EXPORT ZTH_INLINE int zth_zmq_msg_recv(zmq_msg_t* msg, void* socket, int flags)
85 {
86  return zth::zmq::zmq_msg_recv(msg, socket, flags);
87 }
88 
94 EXTERN_C ZTH_EXPORT ZTH_INLINE int
95 zth_zmq_send(void* socket, void const* buf, size_t len, int flags)
96 {
97  return zth::zmq::zmq_send(socket, buf, len, flags);
98 }
99 
105 EXTERN_C ZTH_EXPORT ZTH_INLINE int zth_zmq_recv(void* socket, void* buf, size_t len, int flags)
106 {
107  return zth::zmq::zmq_recv(socket, buf, len, flags);
108 }
109 
115 EXTERN_C ZTH_EXPORT ZTH_INLINE int
116 zth_zmq_send_const(void* socket, void const* buf, size_t len, int flags)
117 {
118  return zth::zmq::zmq_send_const(socket, buf, len, flags);
119 }
120 
121 # else // !__cplusplus
122 ZTH_EXPORT void* zth_zmq_socket(int type);
123 ZTH_EXPORT int zth_zmq_msg_send(zmq_msg_t* msg, void* socket, int flags);
124 ZTH_EXPORT int zth_zmq_msg_recv(zmq_msg_t* msg, void* socket, int flags);
125 ZTH_EXPORT int zth_zmq_send(void* socket, void const* buf, size_t len, int flags);
126 ZTH_EXPORT int zth_zmq_recv(void* socket, void* buf, size_t len, int flags);
127 ZTH_EXPORT int zth_zmq_send_const(void* socket, void const* buf, size_t len, int flags);
128 # endif // __cplusplus
129 
130 # define zmq_ctx_new zth_zmq_context
131 # define zmq_ctx_term(c)
132 # define zmq_socket(c, t) zth_zmq_socket(t)
133 # define zmq_msg_send zth_zmq_msg_send
134 # define zmq_msg_recv zth_zmq_msg_recv
135 # define zmq_send zth_zmq_send
136 # define zmq_recv zth_zmq_recv
137 # define zmq_send_const zth_zmq_send_const
138 # endif // ZTH_REDIRECT_ZMQ
139 
140 #endif // ZTH_HAVE_LIBZMQ
141 #endif // ZTH_ZMQ_H
void * zth_zmq_socket(int type)
Fiber-aware wrapper for 0MQ's zmq_socket().
Definition: zmq.h:64
int zth_zmq_recv(void *socket, void *buf, size_t len, int flags)
Fiber-aware wrapper for 0MQ's zmq_recv().
Definition: zmq.h:105
int zth_zmq_msg_recv(zmq_msg_t *msg, void *socket, int flags)
Fiber-aware wrapper for 0MQ's zmq_msg_recv().
Definition: zmq.h:84
int zth_zmq_send_const(void *socket, void const *buf, size_t len, int flags)
Fiber-aware wrapper for 0MQ's zmq_send_const().
Definition: zmq.h:116
int zth_zmq_send(void *socket, void const *buf, size_t len, int flags)
Fiber-aware wrapper for 0MQ's zmq_send().
Definition: zmq.h:95
int zth_zmq_msg_send(zmq_msg_t *msg, void *socket, int flags)
Fiber-aware wrapper for 0MQ's zmq_msg_send().
Definition: zmq.h:74
void * zth_zmq_context()
Returns the (only) 0MQ context, used by all fibers.
Definition: zmq.h:54
int zmq_msg_send(zmq_msg_t *msg, void *socket, int flags)
Fiber-aware wrapper for 0MQ's zmq_msg_send().
Definition: zmq.cpp:73
int zmq_recv(void *socket, void *buf, size_t len, int flags)
Fiber-aware wrapper for 0MQ's zmq_recv().
Definition: zmq.cpp:136
void * zmq_socket(int type)
Fiber-aware wrapper for 0MQ's zmq_socket().
Definition: zmq.cpp:64
int zmq_send(void *socket, void const *buf, size_t len, int flags)
Fiber-aware wrapper for 0MQ's zmq_send().
Definition: zmq.cpp:115
int zmq_msg_recv(zmq_msg_t *msg, void *socket, int flags)
Fiber-aware wrapper for 0MQ's zmq_msg_recv().
Definition: zmq.cpp:94
void * zmq_context()
Returns the (only) 0MQ context, used by all fibers.
Definition: zmq.cpp:53
int zmq_send_const(void *socket, void const *buf, size_t len, int flags)
Fiber-aware wrapper for 0MQ's zmq_send_const().
Definition: zmq.cpp:157
#define ZTH_INLINE
Definition: macros.h:130
Definition: allocator.h:23