6767#define ZMQ_DEPRECATED (msg ) __declspec(deprecated(msg))
6868#elif defined(__GNUC__)
6969#define ZMQ_DEPRECATED (msg ) __attribute__((deprecated(msg)))
70+ #else
71+ #define ZMQ_DEPRECATED (msg )
7072#endif
7173
7274#if defined(ZMQ_CPP17)
9294#define ZMQ_CONSTEXPR_VAR const
9395#define ZMQ_CPP11_DEPRECATED (msg )
9496#endif
95- #if defined(ZMQ_CPP14) && (!defined(_MSC_VER) || _MSC_VER > 1900)
97+ #if defined(ZMQ_CPP14) && (!defined(_MSC_VER) || _MSC_VER > 1900) && (!defined(__GNUC__) || __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ > 3))
9698#define ZMQ_EXTENDED_CONSTEXPR
9799#endif
98100#if defined(ZMQ_CPP17)
145147
146148/* Version macros for compile-time API version detection */
147149#define CPPZMQ_VERSION_MAJOR 4
148- #define CPPZMQ_VERSION_MINOR 8
150+ #define CPPZMQ_VERSION_MINOR 9
149151#define CPPZMQ_VERSION_PATCH 0
150152
151153#define CPPZMQ_VERSION \
@@ -299,66 +301,78 @@ class error_t : public std::exception
299301 int errnum;
300302};
301303
302- inline int poll (zmq_pollitem_t *items_, size_t nitems_, long timeout_ = -1 )
304+ namespace detail {
305+ inline int poll (zmq_pollitem_t *items_, size_t nitems_, long timeout_)
303306{
304307 int rc = zmq_poll (items_, static_cast <int >(nitems_), timeout_);
305308 if (rc < 0 )
306309 throw error_t ();
307310 return rc;
308311}
312+ }
313+
314+ #ifdef ZMQ_CPP11
315+ ZMQ_DEPRECATED (" from 4.8.0, use poll taking std::chrono::duration instead of long" )
316+ inline int poll(zmq_pollitem_t *items_, size_t nitems_, long timeout_)
317+ #else
318+ inline int poll (zmq_pollitem_t *items_, size_t nitems_, long timeout_ = -1 )
319+ #endif
320+ {
321+ return detail::poll (items_, nitems_, timeout_);
322+ }
309323
310324ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
311325inline int poll(zmq_pollitem_t const *items_, size_t nitems_, long timeout_ = -1 )
312326{
313- return poll (const_cast <zmq_pollitem_t *>(items_), nitems_, timeout_);
327+ return detail:: poll (const_cast <zmq_pollitem_t *>(items_), nitems_, timeout_);
314328}
315329
316330#ifdef ZMQ_CPP11
317331ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
318332inline int
319333poll(zmq_pollitem_t const *items, size_t nitems, std::chrono::milliseconds timeout)
320334{
321- return poll (const_cast <zmq_pollitem_t *>(items), nitems,
335+ return detail:: poll (const_cast <zmq_pollitem_t *>(items), nitems,
322336 static_cast <long >(timeout.count ()));
323337}
324338
325339ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
326340inline int poll(std::vector<zmq_pollitem_t > const &items,
327341 std::chrono::milliseconds timeout)
328342{
329- return poll (const_cast <zmq_pollitem_t *>(items.data ()), items.size (),
343+ return detail:: poll (const_cast <zmq_pollitem_t *>(items.data ()), items.size (),
330344 static_cast <long >(timeout.count ()));
331345}
332346
333347ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
334348inline int poll(std::vector<zmq_pollitem_t > const &items, long timeout_ = -1 )
335349{
336- return poll (const_cast <zmq_pollitem_t *>(items.data ()), items.size (), timeout_);
350+ return detail:: poll (const_cast <zmq_pollitem_t *>(items.data ()), items.size (), timeout_);
337351}
338352
339353inline int
340- poll (zmq_pollitem_t *items, size_t nitems, std::chrono::milliseconds timeout)
354+ poll (zmq_pollitem_t *items, size_t nitems, std::chrono::milliseconds timeout = std::chrono::milliseconds{- 1 } )
341355{
342- return poll (items, nitems, static_cast <long >(timeout.count ()));
356+ return detail:: poll (items, nitems, static_cast <long >(timeout.count ()));
343357}
344358
345359inline int poll (std::vector<zmq_pollitem_t > &items,
346- std::chrono::milliseconds timeout)
360+ std::chrono::milliseconds timeout = std::chrono::milliseconds{- 1 } )
347361{
348- return poll (items.data (), items.size (), static_cast <long >(timeout.count ()));
362+ return detail:: poll (items.data (), items.size (), static_cast <long >(timeout.count ()));
349363}
350364
351- ZMQ_DEPRECATED (" from 4.3.1, use poll taking std::chrono instead of long" )
352- inline int poll(std::vector<zmq_pollitem_t > &items, long timeout_ = - 1 )
365+ ZMQ_DEPRECATED (" from 4.3.1, use poll taking std::chrono::duration instead of long" )
366+ inline int poll(std::vector<zmq_pollitem_t > &items, long timeout_)
353367{
354- return poll (items.data (), items.size (), timeout_);
368+ return detail:: poll (items.data (), items.size (), timeout_);
355369}
356370
357371template <std::size_t SIZE>
358372inline int poll (std::array<zmq_pollitem_t , SIZE> &items,
359- std::chrono::milliseconds timeout)
373+ std::chrono::milliseconds timeout = std::chrono::milliseconds{- 1 } )
360374{
361- return poll (items.data (), items.size (), static_cast <long >(timeout.count ()));
375+ return detail:: poll (items.data (), items.size (), static_cast <long >(timeout.count ()));
362376}
363377#endif
364378
@@ -851,7 +865,7 @@ class context_t
851865
852866 int rc;
853867 do {
854- rc = zmq_ctx_destroy (ptr);
868+ rc = zmq_ctx_term (ptr);
855869 } while (rc == -1 && errno == EINTR);
856870
857871 ZMQ_ASSERT (rc == 0 );
@@ -1362,6 +1376,39 @@ constexpr const_buffer operator"" _zbuf(const char32_t *str, size_t len) noexcep
13621376}
13631377}
13641378
1379+ #ifdef ZMQ_CPP11
1380+ enum class socket_type : int
1381+ {
1382+ req = ZMQ_REQ,
1383+ rep = ZMQ_REP,
1384+ dealer = ZMQ_DEALER,
1385+ router = ZMQ_ROUTER,
1386+ pub = ZMQ_PUB,
1387+ sub = ZMQ_SUB,
1388+ xpub = ZMQ_XPUB,
1389+ xsub = ZMQ_XSUB,
1390+ push = ZMQ_PUSH,
1391+ pull = ZMQ_PULL,
1392+ #if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
1393+ server = ZMQ_SERVER,
1394+ client = ZMQ_CLIENT,
1395+ radio = ZMQ_RADIO,
1396+ dish = ZMQ_DISH,
1397+ gather = ZMQ_GATHER,
1398+ scatter = ZMQ_SCATTER,
1399+ dgram = ZMQ_DGRAM,
1400+ #endif
1401+ #if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3)
1402+ peer = ZMQ_PEER,
1403+ channel = ZMQ_CHANNEL,
1404+ #endif
1405+ #if ZMQ_VERSION_MAJOR >= 4
1406+ stream = ZMQ_STREAM,
1407+ #endif
1408+ pair = ZMQ_PAIR
1409+ };
1410+ #endif
1411+
13651412namespace sockopt
13661413{
13671414// There are two types of options,
@@ -1503,6 +1550,9 @@ ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_MULTICAST_LOOP, multicast_loop, int);
15031550#ifdef ZMQ_MULTICAST_MAXTPDU
15041551ZMQ_DEFINE_INTEGRAL_OPT (ZMQ_MULTICAST_MAXTPDU, multicast_maxtpdu, int );
15051552#endif
1553+ #ifdef ZMQ_ONLY_FIRST_SUBSCRIBE
1554+ ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT (ZMQ_ONLY_FIRST_SUBSCRIBE, only_first_subscribe, int );
1555+ #endif
15061556#ifdef ZMQ_PLAIN_SERVER
15071557ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT (ZMQ_PLAIN_SERVER, plain_server, int );
15081558#endif
@@ -1601,7 +1651,10 @@ ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_TOS, tos, int);
16011651#endif
16021652#ifdef ZMQ_TYPE
16031653ZMQ_DEFINE_INTEGRAL_OPT (ZMQ_TYPE, type, int );
1604- #endif
1654+ #ifdef ZMQ_CPP11
1655+ ZMQ_DEFINE_INTEGRAL_OPT (ZMQ_TYPE, socket_type, socket_type);
1656+ #endif // ZMQ_CPP11
1657+ #endif // ZMQ_TYPE
16051658#ifdef ZMQ_UNSUBSCRIBE
16061659ZMQ_DEFINE_ARRAY_OPT (ZMQ_UNSUBSCRIBE, unsubscribe);
16071660#endif
@@ -1743,7 +1796,7 @@ class socket_base
17431796 template <int Opt, class T , bool BoolUnit>
17441797 ZMQ_NODISCARD T get (sockopt::integral_option<Opt, T, BoolUnit>) const
17451798 {
1746- static_assert (std::is_integral <T>::value, " T must be integral " );
1799+ static_assert (std::is_scalar <T>::value, " T must be scalar " );
17471800 T val;
17481801 size_t size = sizeof val;
17491802 get_option (Opt, &val, &size);
@@ -2012,32 +2065,6 @@ class socket_base
20122065};
20132066} // namespace detail
20142067
2015- #ifdef ZMQ_CPP11
2016- enum class socket_type : int
2017- {
2018- req = ZMQ_REQ,
2019- rep = ZMQ_REP,
2020- dealer = ZMQ_DEALER,
2021- router = ZMQ_ROUTER,
2022- pub = ZMQ_PUB,
2023- sub = ZMQ_SUB,
2024- xpub = ZMQ_XPUB,
2025- xsub = ZMQ_XSUB,
2026- push = ZMQ_PUSH,
2027- pull = ZMQ_PULL,
2028- #if defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 0)
2029- server = ZMQ_SERVER,
2030- client = ZMQ_CLIENT,
2031- radio = ZMQ_RADIO,
2032- dish = ZMQ_DISH,
2033- #endif
2034- #if ZMQ_VERSION_MAJOR >= 4
2035- stream = ZMQ_STREAM,
2036- #endif
2037- pair = ZMQ_PAIR
2038- };
2039- #endif
2040-
20412068struct from_handle_t
20422069{
20432070 struct _private
@@ -2315,7 +2342,11 @@ class monitor_t
23152342 {_monitor_socket.handle (), 0 , ZMQ_POLLIN, 0 },
23162343 };
23172344
2345+ #ifdef ZMQ_CPP11
2346+ zmq::poll (&items[0 ], 1 , std::chrono::milliseconds (timeout));
2347+ #else
23182348 zmq::poll (&items[0 ], 1 , timeout);
2349+ #endif
23192350
23202351 if (items[0 ].revents & ZMQ_POLLIN) {
23212352 int rc = zmq_msg_recv (eventMsg.handle (), _monitor_socket.handle (), 0 );
@@ -2390,8 +2421,7 @@ class monitor_t
23902421 case ZMQ_EVENT_DISCONNECTED:
23912422 on_event_disconnected (*event, address.c_str ());
23922423 break ;
2393- #ifdef ZMQ_BUILD_DRAFT_API
2394- #if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 3)
2424+ #if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 0) || (defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 3))
23952425 case ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL:
23962426 on_event_handshake_failed_no_detail (*event, address.c_str ());
23972427 break ;
@@ -2404,14 +2434,13 @@ class monitor_t
24042434 case ZMQ_EVENT_HANDSHAKE_SUCCEEDED:
24052435 on_event_handshake_succeeded (*event, address.c_str ());
24062436 break ;
2407- #elif ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 1)
2437+ #elif defined(ZMQ_BUILD_DRAFT_API) && ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 2, 1)
24082438 case ZMQ_EVENT_HANDSHAKE_FAILED:
24092439 on_event_handshake_failed (*event, address.c_str ());
24102440 break ;
24112441 case ZMQ_EVENT_HANDSHAKE_SUCCEED:
24122442 on_event_handshake_succeed (*event, address.c_str ());
24132443 break ;
2414- #endif
24152444#endif
24162445 default :
24172446 on_event_unknown (*event, address.c_str ());
@@ -2685,4 +2714,3 @@ inline std::ostream &operator<<(std::ostream &os, const message_t &msg)
26852714} // namespace zmq
26862715
26872716#endif // __ZMQ_HPP_INCLUDED__
2688-
0 commit comments