25 #ifndef __ZMQ_HPP_INCLUDED__
26 #define __ZMQ_HPP_INCLUDED__
36 #if (defined(__GNUC__) && (__GNUC__ > 4 || \
37 (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) && \
38 defined(__GXX_EXPERIMENTAL_CXX0X__))
39 #define ZMQ_HAS_RVALUE_REFS
40 #define ZMQ_DELETED_FUNCTION = delete
41 #elif defined(__clang__)
42 #if __has_feature(cxx_rvalue_references)
43 #define ZMQ_HAS_RVALUE_REFS
46 #if __has_feature(cxx_deleted_functions)
47 #define ZMQ_DELETED_FUNCTION = delete
49 #elif defined(_MSC_VER) && (_MSC_VER >= 1600)
50 #define ZMQ_HAS_RVALUE_REFS
51 #define ZMQ_DELETED_FUNCTION
53 #define ZMQ_DELETED_FUNCTION
59 # define ZMQ_ASSERT(expression) assert(expression)
61 # define ZMQ_ASSERT(expression) (expression)
76 virtual const char *
what ()
const throw ()
78 return zmq_strerror (errnum);
91 inline int poll (zmq_pollitem_t *items_,
int nitems_,
long timeout_ = -1)
93 int rc = zmq_poll (items_, nitems_, timeout_);
99 inline void version (
int *major_,
int *minor_,
int *patch_)
101 zmq_version (major_, minor_, patch_);
112 int rc = zmq_msg_init (&msg);
119 int rc = zmq_msg_init_size (&msg, size_);
127 int rc = zmq_msg_init_data (&msg, data_, size_, ffn_, hint_);
132 #ifdef ZMQ_HAS_RVALUE_REFS
135 int rc = zmq_msg_init (&rhs.msg);
142 std::swap (msg, rhs.msg);
149 int rc = zmq_msg_close (&msg);
155 int rc = zmq_msg_close (&msg);
158 rc = zmq_msg_init (&msg);
165 int rc = zmq_msg_close (&msg);
168 rc = zmq_msg_init_size (&msg, size_);
176 int rc = zmq_msg_close (&msg);
179 rc = zmq_msg_init_data (&msg, data_, size_, ffn_, hint_);
186 int rc = zmq_msg_move (&msg, &(msg_->msg));
193 int rc = zmq_msg_copy (&msg, &(msg_->msg));
200 return zmq_msg_data (&msg);
203 inline const void*
data ()
const
205 return zmq_msg_data (const_cast<zmq_msg_t*>(&msg));
210 return zmq_msg_size (const_cast<zmq_msg_t*>(&msg));
232 ptr = zmq_init (io_threads_);
237 #ifdef ZMQ_HAS_RVALUE_REFS
244 std::swap (ptr, rhs.ptr);
258 int rc = zmq_term (ptr);
266 inline operator void* ()
const
285 ptr = zmq_socket (context_.ptr, type_);
290 #ifdef ZMQ_HAS_RVALUE_REFS
297 std::swap(ptr, rhs.ptr);
307 inline operator void* ()
const
318 int lingerPeriod = 0;
319 int rc = zmq_setsockopt (ptr, ZMQ_LINGER, &lingerPeriod,
sizeof(lingerPeriod));
322 rc = zmq_close (ptr);
330 int rc = zmq_setsockopt (ptr, option_, optval_, optvallen_);
338 int rc = zmq_getsockopt (ptr, option_, optval_, optvallen_);
343 inline void bind (
const char *addr_)
345 int rc = zmq_bind (ptr, addr_);
352 int rc = zmq_connect (ptr, addr_);
362 inline size_t send (
const void *buf_,
size_t len_,
int flags_ = 0)
367 nbytes = zmq_send (ptr, buf_, len_, flags_);
369 return (
size_t) nbytes;
370 if (zmq_errno () == EAGAIN)
372 }
while ((nbytes == -1) && (zmq_errno() == EINTR));
381 nbytes = zmq_msg_send (&(msg_.msg), ptr, flags_);
384 if (zmq_errno () == EAGAIN)
386 }
while ((nbytes == -1) && (zmq_errno() == EINTR));
390 inline size_t recv (
void *buf_,
size_t len_,
int flags_ = 0)
392 int nbytes = zmq_recv (ptr, buf_, len_, flags_);
394 return (
size_t) nbytes;
395 if (zmq_errno () == EAGAIN)
402 int nbytes = zmq_msg_recv (&(msg_->msg), ptr, flags_);
405 if (zmq_errno () == EAGAIN)
415 void operator = (const
socket_t&) ZMQ_DELETED_FUNCTION;