67
67
#define ZMQ_DEPRECATED (msg ) __declspec(deprecated(msg))
68
68
#elif defined(__GNUC__)
69
69
#define ZMQ_DEPRECATED (msg ) __attribute__((deprecated(msg)))
70
+ #else
71
+ #define ZMQ_DEPRECATED (msg )
70
72
#endif
71
73
72
74
#if defined(ZMQ_CPP17)
92
94
#define ZMQ_CONSTEXPR_VAR const
93
95
#define ZMQ_CPP11_DEPRECATED (msg )
94
96
#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))
96
98
#define ZMQ_EXTENDED_CONSTEXPR
97
99
#endif
98
100
#if defined(ZMQ_CPP17)
145
147
146
148
/* Version macros for compile-time API version detection */
147
149
#define CPPZMQ_VERSION_MAJOR 4
148
- #define CPPZMQ_VERSION_MINOR 8
150
+ #define CPPZMQ_VERSION_MINOR 9
149
151
#define CPPZMQ_VERSION_PATCH 0
150
152
151
153
#define CPPZMQ_VERSION \
@@ -299,66 +301,78 @@ class error_t : public std::exception
299
301
int errnum;
300
302
};
301
303
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_)
303
306
{
304
307
int rc = zmq_poll (items_, static_cast <int >(nitems_), timeout_);
305
308
if (rc < 0 )
306
309
throw error_t ();
307
310
return rc;
308
311
}
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
+ }
309
323
310
324
ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
311
325
inline int poll(zmq_pollitem_t const *items_, size_t nitems_, long timeout_ = -1 )
312
326
{
313
- return poll (const_cast <zmq_pollitem_t *>(items_), nitems_, timeout_);
327
+ return detail:: poll (const_cast <zmq_pollitem_t *>(items_), nitems_, timeout_);
314
328
}
315
329
316
330
#ifdef ZMQ_CPP11
317
331
ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
318
332
inline int
319
333
poll(zmq_pollitem_t const *items, size_t nitems, std::chrono::milliseconds timeout)
320
334
{
321
- return poll (const_cast <zmq_pollitem_t *>(items), nitems,
335
+ return detail:: poll (const_cast <zmq_pollitem_t *>(items), nitems,
322
336
static_cast <long >(timeout.count ()));
323
337
}
324
338
325
339
ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
326
340
inline int poll(std::vector<zmq_pollitem_t > const &items,
327
341
std::chrono::milliseconds timeout)
328
342
{
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 (),
330
344
static_cast <long >(timeout.count ()));
331
345
}
332
346
333
347
ZMQ_DEPRECATED (" from 4.3.1, use poll taking non-const items" )
334
348
inline int poll(std::vector<zmq_pollitem_t > const &items, long timeout_ = -1 )
335
349
{
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_);
337
351
}
338
352
339
353
inline 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 } )
341
355
{
342
- return poll (items, nitems, static_cast <long >(timeout.count ()));
356
+ return detail:: poll (items, nitems, static_cast <long >(timeout.count ()));
343
357
}
344
358
345
359
inline int poll (std::vector<zmq_pollitem_t > &items,
346
- std::chrono::milliseconds timeout)
360
+ std::chrono::milliseconds timeout = std::chrono::milliseconds{- 1 } )
347
361
{
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 ()));
349
363
}
350
364
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_)
353
367
{
354
- return poll (items.data (), items.size (), timeout_);
368
+ return detail:: poll (items.data (), items.size (), timeout_);
355
369
}
356
370
357
371
template <std::size_t SIZE>
358
372
inline int poll (std::array<zmq_pollitem_t , SIZE> &items,
359
- std::chrono::milliseconds timeout)
373
+ std::chrono::milliseconds timeout = std::chrono::milliseconds{- 1 } )
360
374
{
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 ()));
362
376
}
363
377
#endif
364
378
@@ -851,7 +865,7 @@ class context_t
851
865
852
866
int rc;
853
867
do {
854
- rc = zmq_ctx_destroy (ptr);
868
+ rc = zmq_ctx_term (ptr);
855
869
} while (rc == -1 && errno == EINTR);
856
870
857
871
ZMQ_ASSERT (rc == 0 );
@@ -1362,6 +1376,39 @@ constexpr const_buffer operator"" _zbuf(const char32_t *str, size_t len) noexcep
1362
1376
}
1363
1377
}
1364
1378
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
+
1365
1412
namespace sockopt
1366
1413
{
1367
1414
// There are two types of options,
@@ -1503,6 +1550,9 @@ ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT(ZMQ_MULTICAST_LOOP, multicast_loop, int);
1503
1550
#ifdef ZMQ_MULTICAST_MAXTPDU
1504
1551
ZMQ_DEFINE_INTEGRAL_OPT (ZMQ_MULTICAST_MAXTPDU, multicast_maxtpdu, int );
1505
1552
#endif
1553
+ #ifdef ZMQ_ONLY_FIRST_SUBSCRIBE
1554
+ ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT (ZMQ_ONLY_FIRST_SUBSCRIBE, only_first_subscribe, int );
1555
+ #endif
1506
1556
#ifdef ZMQ_PLAIN_SERVER
1507
1557
ZMQ_DEFINE_INTEGRAL_BOOL_UNIT_OPT (ZMQ_PLAIN_SERVER, plain_server, int );
1508
1558
#endif
@@ -1601,7 +1651,10 @@ ZMQ_DEFINE_INTEGRAL_OPT(ZMQ_TOS, tos, int);
1601
1651
#endif
1602
1652
#ifdef ZMQ_TYPE
1603
1653
ZMQ_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
1605
1658
#ifdef ZMQ_UNSUBSCRIBE
1606
1659
ZMQ_DEFINE_ARRAY_OPT (ZMQ_UNSUBSCRIBE, unsubscribe);
1607
1660
#endif
@@ -1743,7 +1796,7 @@ class socket_base
1743
1796
template <int Opt, class T , bool BoolUnit>
1744
1797
ZMQ_NODISCARD T get (sockopt::integral_option<Opt, T, BoolUnit>) const
1745
1798
{
1746
- static_assert (std::is_integral <T>::value, " T must be integral " );
1799
+ static_assert (std::is_scalar <T>::value, " T must be scalar " );
1747
1800
T val;
1748
1801
size_t size = sizeof val;
1749
1802
get_option (Opt, &val, &size);
@@ -2012,32 +2065,6 @@ class socket_base
2012
2065
};
2013
2066
} // namespace detail
2014
2067
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
-
2041
2068
struct from_handle_t
2042
2069
{
2043
2070
struct _private
@@ -2315,7 +2342,11 @@ class monitor_t
2315
2342
{_monitor_socket.handle (), 0 , ZMQ_POLLIN, 0 },
2316
2343
};
2317
2344
2345
+ #ifdef ZMQ_CPP11
2346
+ zmq::poll (&items[0 ], 1 , std::chrono::milliseconds (timeout));
2347
+ #else
2318
2348
zmq::poll (&items[0 ], 1 , timeout);
2349
+ #endif
2319
2350
2320
2351
if (items[0 ].revents & ZMQ_POLLIN) {
2321
2352
int rc = zmq_msg_recv (eventMsg.handle (), _monitor_socket.handle (), 0 );
@@ -2390,8 +2421,7 @@ class monitor_t
2390
2421
case ZMQ_EVENT_DISCONNECTED:
2391
2422
on_event_disconnected (*event, address.c_str ());
2392
2423
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))
2395
2425
case ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL:
2396
2426
on_event_handshake_failed_no_detail (*event, address.c_str ());
2397
2427
break ;
@@ -2404,14 +2434,13 @@ class monitor_t
2404
2434
case ZMQ_EVENT_HANDSHAKE_SUCCEEDED:
2405
2435
on_event_handshake_succeeded (*event, address.c_str ());
2406
2436
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)
2408
2438
case ZMQ_EVENT_HANDSHAKE_FAILED:
2409
2439
on_event_handshake_failed (*event, address.c_str ());
2410
2440
break ;
2411
2441
case ZMQ_EVENT_HANDSHAKE_SUCCEED:
2412
2442
on_event_handshake_succeed (*event, address.c_str ());
2413
2443
break ;
2414
- #endif
2415
2444
#endif
2416
2445
default :
2417
2446
on_event_unknown (*event, address.c_str ());
@@ -2685,4 +2714,3 @@ inline std::ostream &operator<<(std::ostream &os, const message_t &msg)
2685
2714
} // namespace zmq
2686
2715
2687
2716
#endif // __ZMQ_HPP_INCLUDED__
2688
-
0 commit comments