6464#define ZMQ_NULLPTR nullptr
6565#define ZMQ_CONSTEXPR_FN constexpr
6666#define ZMQ_CONSTEXPR_VAR constexpr
67+ #define ZMQ_CPP11_DEPRECATED (msg ) ZMQ_DEPRECATED(msg)
6768#else
6869#define ZMQ_NOTHROW throw ()
6970#define ZMQ_EXPLICIT
7071#define ZMQ_OVERRIDE
7172#define ZMQ_NULLPTR 0
7273#define ZMQ_CONSTEXPR_FN
7374#define ZMQ_CONSTEXPR_VAR const
75+ #define ZMQ_CPP11_DEPRECATED (msg )
7476#endif
7577
7678#include < zmq.h>
@@ -630,6 +632,27 @@ inline void swap(message_t &a, message_t &b) ZMQ_NOTHROW
630632 a.swap (b);
631633}
632634
635+ #ifdef ZMQ_CPP11
636+ enum class ctxopt
637+ {
638+ blocky = ZMQ_BLOCKY,
639+ io_threads = ZMQ_IO_THREADS,
640+ thread_sched_policy = ZMQ_THREAD_SCHED_POLICY,
641+ thread_priority = ZMQ_THREAD_PRIORITY,
642+ thread_affinity_cpu_add = ZMQ_THREAD_AFFINITY_CPU_ADD,
643+ thread_affinity_cpu_remove = ZMQ_THREAD_AFFINITY_CPU_REMOVE,
644+ thread_name_prefix = ZMQ_THREAD_NAME_PREFIX,
645+ max_msgsz = ZMQ_MAX_MSGSZ,
646+ #ifdef ZMQ_ZERO_COPY_RECV
647+ zero_copy_recv = ZMQ_ZERO_COPY_RECV,
648+ #endif
649+ max_sockets = ZMQ_MAX_SOCKETS,
650+ socket_limit = ZMQ_SOCKET_LIMIT,
651+ ipv6 = ZMQ_IPV6,
652+ msg_t_size = ZMQ_MSG_T_SIZE
653+ };
654+ #endif
655+
633656class context_t
634657{
635658 public:
@@ -664,16 +687,38 @@ class context_t
664687 }
665688#endif
666689
690+ ~context_t () ZMQ_NOTHROW { close (); }
691+
692+ ZMQ_CPP11_DEPRECATED (" from 4.7.0, use set taking zmq::ctxopt instead" )
667693 int setctxopt (int option_, int optval_)
668694 {
669695 int rc = zmq_ctx_set (ptr, option_, optval_);
670696 ZMQ_ASSERT (rc == 0 );
671697 return rc;
672698 }
673699
700+ ZMQ_CPP11_DEPRECATED (" from 4.7.0, use get taking zmq::ctxopt instead" )
674701 int getctxopt (int option_) { return zmq_ctx_get (ptr, option_); }
675702
676- ~context_t () ZMQ_NOTHROW { close (); }
703+ #ifdef ZMQ_CPP11
704+ void set (ctxopt option, int optval)
705+ {
706+ int rc = zmq_ctx_set (ptr, static_cast <int >(option), optval);
707+ if (rc == -1 )
708+ throw error_t ();
709+ }
710+
711+ ZMQ_NODISCARD int get (ctxopt option)
712+ {
713+ int rc = zmq_ctx_get (ptr, static_cast <int >(option));
714+ // some options have a default value of -1
715+ // which is unfortunate, and may result in errors
716+ // that don't make sense
717+ if (rc == -1 )
718+ throw error_t ();
719+ return rc;
720+ }
721+ #endif
677722
678723 // Terminates context (see also shutdown()).
679724 void close () ZMQ_NOTHROW
@@ -1266,9 +1311,7 @@ class socket_base
12661311
12671312 bool connected () const ZMQ_NOTHROW { return (_handle != ZMQ_NULLPTR); }
12681313
1269- #ifdef ZMQ_CPP11
1270- ZMQ_DEPRECATED (" from 4.3.1, use send taking a const_buffer and send_flags" )
1271- #endif
1314+ ZMQ_CPP11_DEPRECATED (" from 4.3.1, use send taking a const_buffer and send_flags" )
12721315 size_t send (const void *buf_, size_t len_, int flags_ = 0 )
12731316 {
12741317 int nbytes = zmq_send (_handle, buf_, len_, flags_);
@@ -1279,9 +1322,7 @@ class socket_base
12791322 throw error_t ();
12801323 }
12811324
1282- #ifdef ZMQ_CPP11
1283- ZMQ_DEPRECATED (" from 4.3.1, use send taking message_t and send_flags" )
1284- #endif
1325+ ZMQ_CPP11_DEPRECATED (" from 4.3.1, use send taking message_t and send_flags" )
12851326 bool send (message_t &msg_,
12861327 int flags_ = 0 ) // default until removed
12871328 {
@@ -1294,10 +1335,9 @@ class socket_base
12941335 }
12951336
12961337 template <typename T>
1297- #ifdef ZMQ_CPP11
1298- ZMQ_DEPRECATED (" from 4.4.1, use send taking message_t or buffer (for contiguous "
1299- " ranges), and send_flags" )
1300- #endif
1338+ ZMQ_CPP11_DEPRECATED (
1339+ " from 4.4.1, use send taking message_t or buffer (for contiguous "
1340+ " ranges), and send_flags" )
13011341 bool send (T first, T last, int flags_ = 0 )
13021342 {
13031343 zmq::message_t msg (first, last);
@@ -1310,9 +1350,7 @@ class socket_base
13101350 }
13111351
13121352#ifdef ZMQ_HAS_RVALUE_REFS
1313- #ifdef ZMQ_CPP11
1314- ZMQ_DEPRECATED (" from 4.3.1, use send taking message_t and send_flags" )
1315- #endif
1353+ ZMQ_CPP11_DEPRECATED (" from 4.3.1, use send taking message_t and send_flags" )
13161354 bool send(message_t &&msg_,
13171355 int flags_ = 0 ) // default until removed
13181356 {
@@ -1352,9 +1390,8 @@ class socket_base
13521390 }
13531391#endif
13541392
1355- #ifdef ZMQ_CPP11
1356- ZMQ_DEPRECATED (" from 4.3.1, use recv taking a mutable_buffer and recv_flags" )
1357- #endif
1393+ ZMQ_CPP11_DEPRECATED (
1394+ " from 4.3.1, use recv taking a mutable_buffer and recv_flags" )
13581395 size_t recv (void *buf_, size_t len_, int flags_ = 0 )
13591396 {
13601397 int nbytes = zmq_recv (_handle, buf_, len_, flags_);
@@ -1365,10 +1402,8 @@ class socket_base
13651402 throw error_t ();
13661403 }
13671404
1368- #ifdef ZMQ_CPP11
1369- ZMQ_DEPRECATED (
1405+ ZMQ_CPP11_DEPRECATED (
13701406 " from 4.3.1, use recv taking a reference to message_t and recv_flags" )
1371- #endif
13721407 bool recv (message_t *msg_, int flags_ = 0 )
13731408 {
13741409 int nbytes = zmq_msg_recv (msg_->handle (), _handle, flags_);
0 commit comments