OpenShot Library | libopenshot  0.2.5
zmq.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009-2011 250bpm s.r.o.
3  Copyright (c) 2011 Botond Ballo
4  Copyright (c) 2007-2009 iMatix Corporation
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to
8  deal in the Software without restriction, including without limitation the
9  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  sell copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  IN THE SOFTWARE.
23 */
24 
25 #ifndef __ZMQ_HPP_INCLUDED__
26 #define __ZMQ_HPP_INCLUDED__
27 
28 #if __cplusplus >= 201103L
29 #define ZMQ_CPP11
30 #define ZMQ_NOTHROW noexcept
31 #define ZMQ_EXPLICIT explicit
32 #else
33  #define ZMQ_CPP03
34  #define ZMQ_NOTHROW
35  #define ZMQ_EXPLICIT
36 #endif
37 
38 #include <zmq.h>
39 
40 #include <algorithm>
41 #include <cassert>
42 #include <cstring>
43 #include <string>
44 #include <exception>
45 #include <vector>
46 #include <iterator>
47 
48 #ifdef ZMQ_CPP11
49 #include <chrono>
50 #include <tuple>
51 #endif
52 
53 // Detect whether the compiler supports C++11 rvalue references.
54 #if (defined(__GNUC__) && (__GNUC__ > 4 || \
55  (__GNUC__ == 4 && __GNUC_MINOR__ > 2)) && \
56  defined(__GXX_EXPERIMENTAL_CXX0X__))
57  #define ZMQ_HAS_RVALUE_REFS
58  #define ZMQ_DELETED_FUNCTION = delete
59 #elif defined(__clang__)
60  #if __has_feature(cxx_rvalue_references)
61  #define ZMQ_HAS_RVALUE_REFS
62  #endif
63 
64  #if __has_feature(cxx_deleted_functions)
65  #define ZMQ_DELETED_FUNCTION = delete
66  #else
67  #define ZMQ_DELETED_FUNCTION
68  #endif
69 #elif defined(_MSC_VER) && (_MSC_VER >= 1600)
70  #define ZMQ_HAS_RVALUE_REFS
71  #define ZMQ_DELETED_FUNCTION
72 #else
73  #define ZMQ_DELETED_FUNCTION
74 #endif
75 
76 #if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3, 3, 0)
77 #define ZMQ_NEW_MONITOR_EVENT_LAYOUT
78 #endif
79 
80 #if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 1, 0)
81 #define ZMQ_HAS_PROXY_STEERABLE
82 /* Socket event data */
83 typedef struct {
84  uint16_t event; // id of the event as bitfield
85  int32_t value ; // value is either error code, fd or reconnect interval
86 } zmq_event_t;
87 #endif
88 
89 // Avoid using deprecated message receive function when possible
90 #if ZMQ_VERSION < ZMQ_MAKE_VERSION(3, 2, 0)
91 # define zmq_msg_recv(msg, socket, flags) zmq_recvmsg(socket, msg, flags)
92 #endif
93 
94 
95 // In order to prevent unused variable warnings when building in non-debug
96 // mode use this macro to make assertions.
97 #ifndef NDEBUG
98 # define ZMQ_ASSERT(expression) assert(expression)
99 #else
100 # define ZMQ_ASSERT(expression) (void)(expression)
101 #endif
102 
103 namespace zmq
104 {
105 
106  typedef zmq_free_fn free_fn;
107  typedef zmq_pollitem_t pollitem_t;
108 
109  class error_t : public std::exception
110  {
111  public:
112 
113  error_t () : errnum (zmq_errno ()) {}
114 
115  virtual const char *what () const throw ()
116  {
117  return zmq_strerror (errnum);
118  }
119 
120  int num () const
121  {
122  return errnum;
123  }
124 
125  private:
126 
127  int errnum;
128  };
129 
130  inline int poll (zmq_pollitem_t const* items_, size_t nitems_, long timeout_ = -1)
131  {
132  int rc = zmq_poll (const_cast<zmq_pollitem_t*>(items_), static_cast<int>(nitems_), timeout_);
133  if (rc < 0)
134  throw error_t ();
135  return rc;
136  }
137 
138  inline int poll(zmq_pollitem_t const* items, size_t nitems)
139  {
140  return poll(items, nitems, -1);
141  }
142 
143  #ifdef ZMQ_CPP11
144  inline int poll(zmq_pollitem_t const* items, size_t nitems, std::chrono::milliseconds timeout)
145  {
146  return poll(items, nitems, timeout.count() );
147  }
148 
149  inline int poll(std::vector<zmq_pollitem_t> const& items, std::chrono::milliseconds timeout)
150  {
151  return poll(items.data(), items.size(), timeout.count() );
152  }
153 
154  inline int poll(std::vector<zmq_pollitem_t> const& items, long timeout_ = -1)
155  {
156  return poll(items.data(), items.size(), timeout_);
157  }
158  #endif
159 
160 
161 
162  inline void proxy (void *frontend, void *backend, void *capture)
163  {
164  int rc = zmq_proxy (frontend, backend, capture);
165  if (rc != 0)
166  throw error_t ();
167  }
168 
169 #ifdef ZMQ_HAS_PROXY_STEERABLE
170  inline void proxy_steerable (void *frontend, void *backend, void *capture, void *control)
171  {
172  int rc = zmq_proxy_steerable (frontend, backend, capture, control);
173  if (rc != 0)
174  throw error_t ();
175  }
176 #endif
177 
178  inline void version (int *major_, int *minor_, int *patch_)
179  {
180  zmq_version (major_, minor_, patch_);
181  }
182 
183  #ifdef ZMQ_CPP11
184  inline std::tuple<int, int, int> version()
185  {
186  std::tuple<int, int, int> v;
187  zmq_version(&std::get<0>(v), &std::get<1>(v), &std::get<2>(v) );
188  return v;
189  }
190  #endif
191 
192  class message_t
193  {
194  friend class socket_t;
195 
196  public:
197 
198  inline message_t ()
199  {
200  int rc = zmq_msg_init (&msg);
201  if (rc != 0)
202  throw error_t ();
203  }
204 
205  inline explicit message_t (size_t size_)
206  {
207  int rc = zmq_msg_init_size (&msg, size_);
208  if (rc != 0)
209  throw error_t ();
210  }
211 
212  template<typename I> message_t(I first, I last):
213  msg()
214  {
215  typedef typename std::iterator_traits<I>::difference_type size_type;
216  typedef typename std::iterator_traits<I>::value_type value_t;
217 
218  size_type const size_ = std::distance(first, last)*sizeof(value_t);
219  int const rc = zmq_msg_init_size (&msg, size_);
220  if (rc != 0)
221  throw error_t ();
222  value_t* dest = data<value_t>();
223  while (first != last)
224  {
225  *dest = *first;
226  ++dest; ++first;
227  }
228  }
229 
230  inline message_t (const void *data_, size_t size_)
231  {
232  int rc = zmq_msg_init_size (&msg, size_);
233  if (rc != 0)
234  throw error_t ();
235  memcpy(data(), data_, size_);
236  }
237 
238  inline message_t (void *data_, size_t size_, free_fn *ffn_,
239  void *hint_ = NULL)
240  {
241  int rc = zmq_msg_init_data (&msg, data_, size_, ffn_, hint_);
242  if (rc != 0)
243  throw error_t ();
244  }
245 
246 #ifdef ZMQ_HAS_RVALUE_REFS
247  inline message_t (message_t &&rhs): msg (rhs.msg)
248  {
249  int rc = zmq_msg_init (&rhs.msg);
250  if (rc != 0)
251  throw error_t ();
252  }
253 
254  inline message_t &operator = (message_t &&rhs) ZMQ_NOTHROW
255  {
256  std::swap (msg, rhs.msg);
257  return *this;
258  }
259 #endif
260 
262  {
263  int rc = zmq_msg_close (&msg);
264  ZMQ_ASSERT (rc == 0);
265  }
266 
267  inline void rebuild ()
268  {
269  int rc = zmq_msg_close (&msg);
270  if (rc != 0)
271  throw error_t ();
272  rc = zmq_msg_init (&msg);
273  if (rc != 0)
274  throw error_t ();
275  }
276 
277  inline void rebuild (size_t size_)
278  {
279  int rc = zmq_msg_close (&msg);
280  if (rc != 0)
281  throw error_t ();
282  rc = zmq_msg_init_size (&msg, size_);
283  if (rc != 0)
284  throw error_t ();
285  }
286 
287  inline void rebuild (const void *data_, size_t size_)
288  {
289  int rc = zmq_msg_close (&msg);
290  if (rc != 0)
291  throw error_t ();
292  rc = zmq_msg_init_size (&msg, size_);
293  if (rc != 0)
294  throw error_t ();
295  memcpy(data(), data_, size_);
296  }
297 
298  inline void rebuild (void *data_, size_t size_, free_fn *ffn_,
299  void *hint_ = NULL)
300  {
301  int rc = zmq_msg_close (&msg);
302  if (rc != 0)
303  throw error_t ();
304  rc = zmq_msg_init_data (&msg, data_, size_, ffn_, hint_);
305  if (rc != 0)
306  throw error_t ();
307  }
308 
309  inline void move (message_t const *msg_)
310  {
311  int rc = zmq_msg_move (&msg, const_cast<zmq_msg_t*>(&(msg_->msg)));
312  if (rc != 0)
313  throw error_t ();
314  }
315 
316  inline void copy (message_t const *msg_)
317  {
318  int rc = zmq_msg_copy (&msg, const_cast<zmq_msg_t*>(&(msg_->msg)));
319  if (rc != 0)
320  throw error_t ();
321  }
322 
323  inline bool more () const ZMQ_NOTHROW
324  {
325  int rc = zmq_msg_more (const_cast<zmq_msg_t*>(&msg) );
326  return rc != 0;
327  }
328 
329  inline void *data () ZMQ_NOTHROW
330  {
331  return zmq_msg_data (&msg);
332  }
333 
334  inline const void* data () const ZMQ_NOTHROW
335  {
336  return zmq_msg_data (const_cast<zmq_msg_t*>(&msg));
337  }
338 
339  inline size_t size () const ZMQ_NOTHROW
340  {
341  return zmq_msg_size (const_cast<zmq_msg_t*>(&msg));
342  }
343 
344  template<typename T> T* data() ZMQ_NOTHROW
345  {
346  return static_cast<T*>( data() );
347  }
348 
349  template<typename T> T const* data() const ZMQ_NOTHROW
350  {
351  return static_cast<T const*>( data() );
352  }
353 
354 
355  private:
356  // The underlying message
357  zmq_msg_t msg;
358 
359  // Disable implicit message copying, so that users won't use shared
360  // messages (less efficient) without being aware of the fact.
362  void operator = (const message_t&) ZMQ_DELETED_FUNCTION;
363  };
364 
365  class context_t
366  {
367  friend class socket_t;
368 
369  public:
370  inline context_t ()
371  {
372  ptr = zmq_ctx_new ();
373  if (ptr == NULL)
374  throw error_t ();
375  }
376 
377 
378  inline explicit context_t (int io_threads_, int max_sockets_ = ZMQ_MAX_SOCKETS_DFLT)
379  {
380  ptr = zmq_ctx_new ();
381  if (ptr == NULL)
382  throw error_t ();
383 
384  int rc = zmq_ctx_set (ptr, ZMQ_IO_THREADS, io_threads_);
385  ZMQ_ASSERT (rc == 0);
386 
387  rc = zmq_ctx_set (ptr, ZMQ_MAX_SOCKETS, max_sockets_);
388  ZMQ_ASSERT (rc == 0);
389  }
390 
391 #ifdef ZMQ_HAS_RVALUE_REFS
392  inline context_t (context_t &&rhs) ZMQ_NOTHROW : ptr (rhs.ptr)
393  {
394  rhs.ptr = NULL;
395  }
396  inline context_t &operator = (context_t &&rhs) ZMQ_NOTHROW
397  {
398  std::swap (ptr, rhs.ptr);
399  return *this;
400  }
401 #endif
402 
404  {
405  int rc = zmq_ctx_destroy (ptr);
406  ZMQ_ASSERT (rc == 0);
407  }
408 
409  inline void close() ZMQ_NOTHROW
410  {
411  int rc = zmq_ctx_destroy (ptr);
412  ZMQ_ASSERT (rc == 0);
413  }
414 
415  // Be careful with this, it's probably only useful for
416  // using the C api together with an existing C++ api.
417  // Normally you should never need to use this.
418  inline ZMQ_EXPLICIT operator void* () ZMQ_NOTHROW
419  {
420  return ptr;
421  }
422 
423  inline ZMQ_EXPLICIT operator void const* () const ZMQ_NOTHROW
424  {
425  return ptr;
426  }
427  private:
428 
429  void *ptr;
430 
431  context_t (const context_t&) ZMQ_DELETED_FUNCTION;
432  void operator = (const context_t&) ZMQ_DELETED_FUNCTION;
433  };
434 
435  #ifdef ZMQ_CPP11
436  enum class socket_type: int
437  {
438  req = ZMQ_REQ,
439  rep = ZMQ_REP,
440  dealer = ZMQ_DEALER,
441  router = ZMQ_ROUTER,
442  pub = ZMQ_PUB,
443  sub = ZMQ_SUB,
444  xpub = ZMQ_XPUB,
445  xsub = ZMQ_XSUB,
446  push = ZMQ_PUSH,
447  pull = ZMQ_PULL,
448 #if ZMQ_VERSION_MAJOR < 4
449  pair = ZMQ_PAIR
450 #else
451  pair = ZMQ_PAIR,
452  stream = ZMQ_STREAM
453 #endif
454  };
455  #endif
456 
457  class socket_t
458  {
459  friend class monitor_t;
460  public:
461  inline socket_t(context_t& context_, int type_)
462  {
463  init(context_, type_);
464  }
465 
466  #ifdef ZMQ_CPP11
467  inline socket_t(context_t& context_, socket_type type_)
468  {
469  init(context_, static_cast<int>(type_));
470  }
471  #endif
472 
473 #ifdef ZMQ_HAS_RVALUE_REFS
474  inline socket_t(socket_t&& rhs) ZMQ_NOTHROW : ptr(rhs.ptr)
475  {
476  rhs.ptr = NULL;
477  }
478  inline socket_t& operator=(socket_t&& rhs) ZMQ_NOTHROW
479  {
480  std::swap(ptr, rhs.ptr);
481  return *this;
482  }
483 #endif
484 
486  {
487  close();
488  }
489 
490  inline ZMQ_EXPLICIT operator void* () ZMQ_NOTHROW
491  {
492  return ptr;
493  }
494 
495  inline ZMQ_EXPLICIT operator void const* () const ZMQ_NOTHROW
496  {
497  return ptr;
498  }
499 
500  inline void close() ZMQ_NOTHROW
501  {
502  if(ptr == NULL)
503  // already closed
504  return ;
505  int rc = zmq_close (ptr);
506  ZMQ_ASSERT (rc == 0);
507  ptr = 0 ;
508  }
509 
510  template<typename T> void setsockopt(int option_, T const& optval)
511  {
512  setsockopt(option_, &optval, sizeof(T) );
513  }
514 
515  inline void setsockopt (int option_, const void *optval_,
516  size_t optvallen_)
517  {
518  int rc = zmq_setsockopt (ptr, option_, optval_, optvallen_);
519  if (rc != 0)
520  throw error_t ();
521  }
522 
523  inline void getsockopt (int option_, void *optval_,
524  size_t *optvallen_) const
525  {
526  int rc = zmq_getsockopt (ptr, option_, optval_, optvallen_);
527  if (rc != 0)
528  throw error_t ();
529  }
530 
531  template<typename T> T getsockopt(int option_) const
532  {
533  T optval;
534  size_t optlen = sizeof(T);
535  getsockopt(option_, &optval, &optlen );
536  return optval;
537  }
538 
539  inline void bind(std::string const& addr)
540  {
541  bind(addr.c_str());
542  }
543 
544  inline void bind (const char *addr_)
545  {
546  int rc = zmq_bind (ptr, addr_);
547  if (rc != 0)
548  throw error_t ();
549  }
550 
551  inline void unbind(std::string const& addr)
552  {
553  unbind(addr.c_str());
554  }
555 
556  inline void unbind (const char *addr_)
557  {
558  int rc = zmq_unbind (ptr, addr_);
559  if (rc != 0)
560  throw error_t ();
561  }
562 
563  inline void connect(std::string const& addr)
564  {
565  connect(addr.c_str());
566  }
567 
568  inline void connect (const char *addr_)
569  {
570  int rc = zmq_connect (ptr, addr_);
571  if (rc != 0)
572  throw error_t ();
573  }
574 
575  inline void disconnect(std::string const& addr)
576  {
577  disconnect(addr.c_str());
578  }
579 
580  inline void disconnect (const char *addr_)
581  {
582  int rc = zmq_disconnect (ptr, addr_);
583  if (rc != 0)
584  throw error_t ();
585  }
586 
587  inline bool connected() const ZMQ_NOTHROW
588  {
589  return(ptr != NULL);
590  }
591 
592  inline size_t send (const void *buf_, size_t len_, int flags_ = 0)
593  {
594  int nbytes = zmq_send (ptr, buf_, len_, flags_);
595  if (nbytes >= 0)
596  return (size_t) nbytes;
597  if (zmq_errno () == EAGAIN)
598  return 0;
599  throw error_t ();
600  }
601 
602  inline bool send (message_t &msg_, int flags_ = 0)
603  {
604  int nbytes = zmq_msg_send (&(msg_.msg), ptr, flags_);
605  if (nbytes >= 0)
606  return true;
607  if (zmq_errno () == EAGAIN)
608  return false;
609  throw error_t ();
610  }
611 
612  template<typename I> bool send(I first, I last, int flags_=0)
613  {
614  zmq::message_t msg(first, last);
615  return send(msg, flags_);
616  }
617 
618 #ifdef ZMQ_HAS_RVALUE_REFS
619  inline bool send (message_t &&msg_, int flags_ = 0)
620  {
621  return send(msg_, flags_);
622  }
623 #endif
624 
625  inline size_t recv (void *buf_, size_t len_, int flags_ = 0)
626  {
627  int nbytes = zmq_recv (ptr, buf_, len_, flags_);
628  if (nbytes >= 0)
629  return (size_t) nbytes;
630  if (zmq_errno () == EAGAIN)
631  return 0;
632  throw error_t ();
633  }
634 
635  inline bool recv (message_t *msg_, int flags_ = 0)
636  {
637  int nbytes = zmq_msg_recv (&(msg_->msg), ptr, flags_);
638  if (nbytes >= 0)
639  return true;
640  if (zmq_errno () == EAGAIN)
641  return false;
642  throw error_t ();
643  }
644 
645  private:
646  inline void init(context_t& context_, int type_)
647  {
648  ctxptr = context_.ptr;
649  ptr = zmq_socket (context_.ptr, type_ );
650  if (ptr == NULL)
651  throw error_t ();
652  }
653 
654  void *ptr;
655  void *ctxptr;
656 
657  socket_t (const socket_t&) ZMQ_DELETED_FUNCTION;
658  void operator = (const socket_t&) ZMQ_DELETED_FUNCTION;
659  };
660 
661  class monitor_t
662  {
663  public:
664  monitor_t() : socketPtr(NULL) {}
665  virtual ~monitor_t() {}
666 
667  void monitor(socket_t &socket, std::string const& addr, int events = ZMQ_EVENT_ALL)
668  {
669  monitor(socket, addr.c_str(), events);
670  }
671 
672  void monitor(socket_t &socket, const char *addr_, int events = ZMQ_EVENT_ALL)
673  {
674  int rc = zmq_socket_monitor(socket.ptr, addr_, events);
675  if (rc != 0)
676  throw error_t ();
677 
678  socketPtr = socket.ptr;
679  void *s = zmq_socket (socket.ctxptr, ZMQ_PAIR);
680  assert (s);
681 
682  rc = zmq_connect (s, addr_);
683  assert (rc == 0);
684 
685  on_monitor_started();
686 
687  while (true) {
688  zmq_msg_t eventMsg;
689  zmq_msg_init (&eventMsg);
690  rc = zmq_msg_recv (&eventMsg, s, 0);
691  if (rc == -1 && zmq_errno() == ETERM)
692  break;
693  assert (rc != -1);
694 #if ZMQ_VERSION_MAJOR >= 4
695  const char* data = static_cast<const char*>(zmq_msg_data(&eventMsg));
696  zmq_event_t msgEvent;
697  memcpy(&msgEvent.event, data, sizeof(uint16_t)); data += sizeof(uint16_t);
698  memcpy(&msgEvent.value, data, sizeof(int32_t));
699  zmq_event_t* event = &msgEvent;
700 #else
701  zmq_event_t* event = static_cast<zmq_event_t*>(zmq_msg_data(&eventMsg));
702 #endif
703 
704 #ifdef ZMQ_NEW_MONITOR_EVENT_LAYOUT
705  zmq_msg_t addrMsg;
706  zmq_msg_init (&addrMsg);
707  rc = zmq_msg_recv (&addrMsg, s, 0);
708  if (rc == -1 && zmq_errno() == ETERM)
709  break;
710  assert (rc != -1);
711  const char* str = static_cast<const char*>(zmq_msg_data (&addrMsg));
712  std::string address(str, str + zmq_msg_size(&addrMsg));
713  zmq_msg_close (&addrMsg);
714 #else
715  // Bit of a hack, but all events in the zmq_event_t union have the same layout so this will work for all event types.
716  std::string address = event->data.connected.addr;
717 #endif
718 
719 #ifdef ZMQ_EVENT_MONITOR_STOPPED
720  if (event->event == ZMQ_EVENT_MONITOR_STOPPED)
721  break;
722 #endif
723 
724  switch (event->event) {
725  case ZMQ_EVENT_CONNECTED:
726  on_event_connected(*event, address.c_str());
727  break;
728  case ZMQ_EVENT_CONNECT_DELAYED:
729  on_event_connect_delayed(*event, address.c_str());
730  break;
731  case ZMQ_EVENT_CONNECT_RETRIED:
732  on_event_connect_retried(*event, address.c_str());
733  break;
734  case ZMQ_EVENT_LISTENING:
735  on_event_listening(*event, address.c_str());
736  break;
737  case ZMQ_EVENT_BIND_FAILED:
738  on_event_bind_failed(*event, address.c_str());
739  break;
740  case ZMQ_EVENT_ACCEPTED:
741  on_event_accepted(*event, address.c_str());
742  break;
743  case ZMQ_EVENT_ACCEPT_FAILED:
744  on_event_accept_failed(*event, address.c_str());
745  break;
746  case ZMQ_EVENT_CLOSED:
747  on_event_closed(*event, address.c_str());
748  break;
749  case ZMQ_EVENT_CLOSE_FAILED:
750  on_event_close_failed(*event, address.c_str());
751  break;
752  case ZMQ_EVENT_DISCONNECTED:
753  on_event_disconnected(*event, address.c_str());
754  break;
755  default:
756  on_event_unknown(*event, address.c_str());
757  break;
758  }
759  zmq_msg_close (&eventMsg);
760  }
761  zmq_close (s);
762  socketPtr = NULL;
763  }
764 
765 #ifdef ZMQ_EVENT_MONITOR_STOPPED
766  void abort()
767  {
768  if (socketPtr)
769  zmq_socket_monitor(socketPtr, NULL, 0);
770  }
771 #endif
772  virtual void on_monitor_started() {}
773  virtual void on_event_connected(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
774  virtual void on_event_connect_delayed(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
775  virtual void on_event_connect_retried(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
776  virtual void on_event_listening(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
777  virtual void on_event_bind_failed(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
778  virtual void on_event_accepted(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
779  virtual void on_event_accept_failed(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
780  virtual void on_event_closed(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
781  virtual void on_event_close_failed(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
782  virtual void on_event_disconnected(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
783  virtual void on_event_unknown(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; }
784  private:
785  void* socketPtr;
786  };
787 }
788 
789 #endif
void monitor(socket_t &socket, const char *addr_, int events=ZMQ_EVENT_ALL)
Definition: zmq.hpp:672
context_t(int io_threads_, int max_sockets_=ZMQ_MAX_SOCKETS_DFLT)
Definition: zmq.hpp:378
#define ZMQ_DELETED_FUNCTION
Definition: zmq.hpp:73
void monitor(socket_t &socket, std::string const &addr, int events=ZMQ_EVENT_ALL)
Definition: zmq.hpp:667
zmq_pollitem_t pollitem_t
Definition: zmq.hpp:107
virtual void on_event_connect_delayed(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:774
void connect(const char *addr_)
Definition: zmq.hpp:568
void close() ZMQ_NOTHROW
Definition: zmq.hpp:409
#define ZMQ_NOTHROW
Definition: zmq.hpp:34
T getsockopt(int option_) const
Definition: zmq.hpp:531
T * data() ZMQ_NOTHROW
Definition: zmq.hpp:344
virtual void on_event_closed(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:780
virtual void on_event_disconnected(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:782
virtual void on_event_accepted(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:778
void rebuild(const void *data_, size_t size_)
Definition: zmq.hpp:287
message_t(const void *data_, size_t size_)
Definition: zmq.hpp:230
size_t send(const void *buf_, size_t len_, int flags_=0)
Definition: zmq.hpp:592
void move(message_t const *msg_)
Definition: zmq.hpp:309
void close() ZMQ_NOTHROW
Definition: zmq.hpp:500
void copy(message_t const *msg_)
Definition: zmq.hpp:316
virtual ~monitor_t()
Definition: zmq.hpp:665
T const * data() const ZMQ_NOTHROW
Definition: zmq.hpp:349
void getsockopt(int option_, void *optval_, size_t *optvallen_) const
Definition: zmq.hpp:523
~message_t() ZMQ_NOTHROW
Definition: zmq.hpp:261
void proxy_steerable(void *frontend, void *backend, void *capture, void *control)
Definition: zmq.hpp:170
void * data() ZMQ_NOTHROW
Definition: zmq.hpp:329
bool send(I first, I last, int flags_=0)
Definition: zmq.hpp:612
zmq_free_fn free_fn
Definition: zmq.hpp:106
int num() const
Definition: zmq.hpp:120
void proxy(void *frontend, void *backend, void *capture)
Definition: zmq.hpp:162
size_t recv(void *buf_, size_t len_, int flags_=0)
Definition: zmq.hpp:625
void rebuild()
Definition: zmq.hpp:267
void bind(std::string const &addr)
Definition: zmq.hpp:539
void disconnect(const char *addr_)
Definition: zmq.hpp:580
const void * data() const ZMQ_NOTHROW
Definition: zmq.hpp:334
void unbind(const char *addr_)
Definition: zmq.hpp:556
virtual void on_event_close_failed(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:781
bool send(message_t &msg_, int flags_=0)
Definition: zmq.hpp:602
virtual const char * what() const
Definition: zmq.hpp:115
#define ZMQ_ASSERT(expression)
Definition: zmq.hpp:98
~socket_t() ZMQ_NOTHROW
Definition: zmq.hpp:485
bool recv(message_t *msg_, int flags_=0)
Definition: zmq.hpp:635
uint16_t event
Definition: zmq.hpp:84
virtual void on_event_unknown(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:783
socket_t(context_t &context_, int type_)
Definition: zmq.hpp:461
void connect(std::string const &addr)
Definition: zmq.hpp:563
void rebuild(size_t size_)
Definition: zmq.hpp:277
message_t(size_t size_)
Definition: zmq.hpp:205
message_t(I first, I last)
Definition: zmq.hpp:212
virtual void on_event_listening(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:776
void version(int *major_, int *minor_, int *patch_)
Definition: zmq.hpp:178
void setsockopt(int option_, const void *optval_, size_t optvallen_)
Definition: zmq.hpp:515
virtual void on_event_connected(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:773
size_t size() const ZMQ_NOTHROW
Definition: zmq.hpp:339
message_t(void *data_, size_t size_, free_fn *ffn_, void *hint_=NULL)
Definition: zmq.hpp:238
virtual void on_monitor_started()
Definition: zmq.hpp:772
virtual void on_event_bind_failed(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:777
virtual void on_event_accept_failed(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:779
bool connected() const ZMQ_NOTHROW
Definition: zmq.hpp:587
friend class socket_t
Definition: zmq.hpp:194
void rebuild(void *data_, size_t size_, free_fn *ffn_, void *hint_=NULL)
Definition: zmq.hpp:298
void unbind(std::string const &addr)
Definition: zmq.hpp:551
~context_t() ZMQ_NOTHROW
Definition: zmq.hpp:403
int poll(zmq_pollitem_t const *items_, size_t nitems_, long timeout_=-1)
Definition: zmq.hpp:130
Definition: zmq.hpp:103
int32_t value
Definition: zmq.hpp:85
#define ZMQ_EXPLICIT
Definition: zmq.hpp:35
void disconnect(std::string const &addr)
Definition: zmq.hpp:575
void setsockopt(int option_, T const &optval)
Definition: zmq.hpp:510
virtual void on_event_connect_retried(const zmq_event_t &event_, const char *addr_)
Definition: zmq.hpp:775
void bind(const char *addr_)
Definition: zmq.hpp:544
bool more() const ZMQ_NOTHROW
Definition: zmq.hpp:323