27
27
#define __ZMQ_HPP_INCLUDED__
28
28
29
29
#if (__cplusplus >= 201103L)
30
- #define ZMQ_CPP11
31
- #define ZMQ_NOTHROW noexcept
32
- #define ZMQ_EXPLICIT explicit
33
- #elif (defined(_MSC_VER) && (_MSC_VER >= 1900))
34
- #define ZMQ_CPP11
35
- #define ZMQ_NOTHROW noexcept
36
- #define ZMQ_EXPLICIT explicit
30
+ #define ZMQ_CPP11
31
+ #define ZMQ_NOTHROW noexcept
32
+ #define ZMQ_EXPLICIT explicit
33
+ #elif (defined(_MSC_VER) && (_MSC_VER >= 1900))
34
+ #define ZMQ_CPP11
35
+ #define ZMQ_NOTHROW noexcept
36
+ #define ZMQ_EXPLICIT explicit
37
37
#else
38
38
#define ZMQ_CPP03
39
39
#define ZMQ_NOTHROW
42
42
43
43
#include < zmq.h>
44
44
45
- #include < algorithm>
46
45
#include < cassert>
47
46
#include < cstring>
48
- #include < string>
47
+
48
+ #include < algorithm>
49
49
#include < exception>
50
- #include < vector >
50
+ #include < iomanip >
51
51
#include < iterator>
52
+ #include < sstream>
53
+ #include < string>
54
+ #include < vector>
55
+
52
56
53
57
#ifdef ZMQ_CPP11
54
- #include < chrono>
55
- #include < tuple>
56
- #include < functional>
58
+ #include < chrono>
59
+ #include < tuple>
60
+ #include < functional>
57
61
#endif
58
62
59
63
// Detect whether the compiler supports C++11 rvalue references.
83
87
#endif
84
88
85
89
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(3, 3, 0)
86
- #define ZMQ_NEW_MONITOR_EVENT_LAYOUT
90
+ #define ZMQ_NEW_MONITOR_EVENT_LAYOUT
87
91
#endif
88
92
89
93
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 1, 0)
90
- #define ZMQ_HAS_PROXY_STEERABLE
94
+ #define ZMQ_HAS_PROXY_STEERABLE
91
95
/* Socket event data */
92
96
typedef struct {
93
97
uint16_t event; // id of the event as bitfield
@@ -378,6 +382,42 @@ namespace zmq
378
382
return value;
379
383
}
380
384
#endif
385
+ /* * Dump content to string. Ascii chars are readable, the rest is printed as hex.
386
+ * Probably ridiculously slow.
387
+ */
388
+ inline std::string str () const
389
+ {
390
+ // Partly mutuated from the same method in zmq::multipart_t
391
+ std::stringstream os;
392
+
393
+ const unsigned char * msg_data = this ->data <unsigned char >();
394
+ unsigned char byte;
395
+ size_t size = this ->size ();
396
+ int is_ascii[2 ] = {0 , 0 };
397
+
398
+ os << " zmq::message_t [size " << std::dec << std::setw (3 ) << std::setfill (' 0' ) << size << " ] (" ;
399
+ // Totally arbitrary
400
+ if (size >= 1000 ) {
401
+ os << " ... too big to print)" ;
402
+ } else {
403
+ while (size--) {
404
+ byte = *msg_data++;
405
+
406
+ is_ascii[1 ] = (byte >= 33 && byte < 127 );
407
+ if (is_ascii[1 ] != is_ascii[0 ])
408
+ os << " " ; // Separate text/non text
409
+
410
+ if (is_ascii[1 ]) {
411
+ os << byte;
412
+ } else {
413
+ os << std::hex << std::uppercase << std::setw (2 ) << std::setfill (' 0' ) << static_cast <short >(byte);
414
+ }
415
+ is_ascii[0 ] = is_ascii[1 ];
416
+ }
417
+ os << " )" ;
418
+ }
419
+ return os.str ();
420
+ }
381
421
382
422
private:
383
423
// The underlying message
@@ -927,7 +967,7 @@ namespace zmq
927
967
#elif ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 1)
928
968
virtual void on_event_handshake_failed (const zmq_event_t &event_, const char * addr_) { (void ) event_; (void ) addr_; }
929
969
virtual void on_event_handshake_succeed (const zmq_event_t &event_, const char * addr_) { (void ) event_; (void ) addr_; }
930
- #endif
970
+ #endif
931
971
virtual void on_event_unknown (const zmq_event_t &event_, const char * addr_) { (void )event_; (void )addr_; }
932
972
private:
933
973
@@ -984,9 +1024,9 @@ namespace zmq
984
1024
985
1025
#if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 3)
986
1026
if (zmq_errno () == EAGAIN)
987
- #else
1027
+ #else
988
1028
if (zmq_errno () == ETIMEDOUT)
989
- #endif
1029
+ #endif
990
1030
return false ;
991
1031
992
1032
throw error_t ();
@@ -995,9 +1035,15 @@ namespace zmq
995
1035
private:
996
1036
void *poller_ptr;
997
1037
std::vector<zmq_poller_event_t > poller_events;
998
- };
1038
+ }; // class poller_t
999
1039
#endif // defined(ZMQ_BUILD_DRAFT_API) && defined(ZMQ_CPP11) && defined(ZMQ_HAVE_POLLER)
1000
1040
1041
+
1042
+ inline std::ostream& operator <<(std::ostream& os, const message_t & msg)
1043
+ {
1044
+ return os << msg.str ();
1001
1045
}
1002
1046
1003
- #endif
1047
+ } // namespace zmq
1048
+
1049
+ #endif // __ZMQ_HPP_INCLUDED__
0 commit comments