diff --git a/zmq.hpp b/zmq.hpp index cfd8e92..b59f1aa 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -35,6 +35,20 @@ // included here for _HAS_CXX* macros #include +#ifdef CPPZMQ_NO_CPP_EXCEPTIONS +#define THROW_ERROR_T std::abort() +#define THROW_ZMQ_ERROR_T std::abort() +#define THROW_RETURN(v) return v +#define NO_THROW_RETURN_TYPE(t) t +#define NO_THROW_RETURN(v) return v +#else +#define THROW_ERROR_T throw error_t() +#define THROW_ZMQ_ERROR_T zmq::error_t() +#define THROW_RETURN(v) throw error_t() +#define NO_THROW_RETURN_TYPE(t) void +#define NO_THROW_RETURN(v) +#endif + #if defined(_MSVC_LANG) #define CPPZMQ_LANG _MSVC_LANG #else @@ -251,8 +265,8 @@ template using iter_value_t = typename std::iterator_traits::value_type; template -using range_iter_t = decltype( - ranges::begin(std::declval::type &>())); +using range_iter_t = decltype(ranges::begin( + std::declval::type &>())); template using range_value_t = iter_value_t>; @@ -263,9 +277,10 @@ template struct is_range : std::false_type template struct is_range< T, - void_t::type &>()) - == ranges::end(std::declval::type &>()))>> + void_t::type &>()) + == ranges::end( + std::declval::type &>()))>> : std::true_type { }; @@ -302,12 +317,13 @@ class error_t : public std::exception int errnum; }; -namespace detail { +namespace detail +{ inline int poll(zmq_pollitem_t *items_, size_t nitems_, long timeout_) { int rc = zmq_poll(items_, static_cast(nitems_), timeout_); if (rc < 0) - throw error_t(); + THROW_RETURN(rc); return rc; } } @@ -334,7 +350,7 @@ inline int poll(zmq_pollitem_t const *items, size_t nitems, std::chrono::milliseconds timeout) { return detail::poll(const_cast(items), nitems, - static_cast(timeout.count())); + static_cast(timeout.count())); } ZMQ_DEPRECATED("from 4.3.1, use poll taking non-const items") @@ -342,17 +358,19 @@ inline int poll(std::vector const &items, std::chrono::milliseconds timeout) { return detail::poll(const_cast(items.data()), items.size(), - static_cast(timeout.count())); + static_cast(timeout.count())); } ZMQ_DEPRECATED("from 4.3.1, use poll taking non-const items") inline int poll(std::vector const &items, long timeout_ = -1) { - return detail::poll(const_cast(items.data()), items.size(), timeout_); + return detail::poll(const_cast(items.data()), items.size(), + timeout_); } -inline int -poll(zmq_pollitem_t *items, size_t nitems, std::chrono::milliseconds timeout = std::chrono::milliseconds{-1}) +inline int poll(zmq_pollitem_t *items, + size_t nitems, + std::chrono::milliseconds timeout = std::chrono::milliseconds{-1}) { return detail::poll(items, nitems, static_cast(timeout.count())); } @@ -360,7 +378,8 @@ poll(zmq_pollitem_t *items, size_t nitems, std::chrono::milliseconds timeout = s inline int poll(std::vector &items, std::chrono::milliseconds timeout = std::chrono::milliseconds{-1}) { - return detail::poll(items.data(), items.size(), static_cast(timeout.count())); + return detail::poll(items.data(), items.size(), + static_cast(timeout.count())); } ZMQ_DEPRECATED("from 4.3.1, use poll taking std::chrono::duration instead of long") @@ -373,7 +392,8 @@ template inline int poll(std::array &items, std::chrono::milliseconds timeout = std::chrono::milliseconds{-1}) { - return detail::poll(items.data(), items.size(), static_cast(timeout.count())); + return detail::poll(items.data(), items.size(), + static_cast(timeout.count())); } #endif @@ -419,7 +439,7 @@ class message_t { int rc = zmq_msg_init_size(&msg, size_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } template message_t(ForwardIter first, ForwardIter last) @@ -431,7 +451,7 @@ class message_t static_cast(std::distance(first, last)) * sizeof(value_t); int const rc = zmq_msg_init_size(&msg, size_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; std::copy(first, last, data()); } @@ -439,7 +459,7 @@ class message_t { int rc = zmq_msg_init_size(&msg, size_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; if (size_) { // this constructor allows (nullptr, 0), // memcpy with a null pointer is UB @@ -451,7 +471,7 @@ class message_t { int rc = zmq_msg_init_data(&msg, data_, size_, ffn_, hint_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } // overload set of string-like types and generic containers @@ -514,7 +534,7 @@ class message_t { int rc = zmq_msg_close(&msg); if (rc != 0) - throw error_t(); + THROW_ERROR_T; rc = zmq_msg_init(&msg); ZMQ_ASSERT(rc == 0); } @@ -523,23 +543,23 @@ class message_t { int rc = zmq_msg_close(&msg); if (rc != 0) - throw error_t(); + THROW_ERROR_T; rc = zmq_msg_init_size(&msg, size_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } void rebuild(const void *data_, size_t size_) { int rc = zmq_msg_close(&msg); if (rc != 0) - throw error_t(); + THROW_ERROR_T; rc = zmq_msg_init_size(&msg, size_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; memcpy(data(), data_, size_); } - + void rebuild(const std::string &str) { rebuild(str.data(), str.size()); @@ -549,10 +569,10 @@ class message_t { int rc = zmq_msg_close(&msg); if (rc != 0) - throw error_t(); + THROW_ERROR_T; rc = zmq_msg_init_data(&msg, data_, size_, ffn_, hint_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } ZMQ_DEPRECATED("from 4.3.1, use move taking non-const reference instead") @@ -560,14 +580,14 @@ class message_t { int rc = zmq_msg_move(&msg, const_cast(msg_->handle())); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } void move(message_t &msg_) { int rc = zmq_msg_move(&msg, msg_.handle()); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } ZMQ_DEPRECATED("from 4.3.1, use copy taking non-const reference instead") @@ -575,14 +595,14 @@ class message_t { int rc = zmq_msg_copy(&msg, const_cast(msg_->handle())); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } void copy(message_t &msg_) { int rc = zmq_msg_copy(&msg, msg_.handle()); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } bool more() const ZMQ_NOTHROW @@ -631,7 +651,7 @@ class message_t { int value = zmq_msg_get(&msg, property_); if (value == -1) - throw error_t(); + THROW_RETURN(value); return value; } #endif @@ -641,7 +661,7 @@ class message_t { const char *value = zmq_msg_gets(&msg, property_); if (value == ZMQ_NULLPTR) - throw error_t(); + THROW_RETURN(value); return value; } #endif @@ -656,7 +676,7 @@ class message_t { int rc = zmq_msg_set_routing_id(&msg, routing_id); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } const char *group() const @@ -668,7 +688,7 @@ class message_t { int rc = zmq_msg_set_group(&msg, group); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } #endif @@ -803,7 +823,7 @@ class context_t { ptr = zmq_ctx_new(); if (ptr == ZMQ_NULLPTR) - throw error_t(); + THROW_ERROR_T; } @@ -811,7 +831,7 @@ class context_t { ptr = zmq_ctx_new(); if (ptr == ZMQ_NULLPTR) - throw error_t(); + THROW_ERROR_T; int rc = zmq_ctx_set(ptr, ZMQ_IO_THREADS, io_threads_); ZMQ_ASSERT(rc == 0); @@ -848,7 +868,7 @@ class context_t { int rc = zmq_ctx_set(ptr, static_cast(option), optval); if (rc == -1) - throw error_t(); + THROW_ERROR_T; } ZMQ_NODISCARD int get(ctxopt option) @@ -858,7 +878,7 @@ class context_t // which is unfortunate, and may result in errors // that don't make sense if (rc == -1) - throw error_t(); + THROW_RETURN(rc); return rc; } #endif @@ -974,13 +994,21 @@ template class trivial_optional T &value() { if (!_has_value) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::exception(); +#else + std::abort(); +#endif return _value; } const T &value() const { if (!_has_value) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::exception(); +#else + std::abort(); +#endif return _value; } @@ -1749,7 +1777,7 @@ class socket_base { int rc = zmq_setsockopt(_handle, option_, optval_, optvallen_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } ZMQ_CPP11_DEPRECATED("from 4.7.0, use `get` taking option from zmq::sockopt") @@ -1757,7 +1785,7 @@ class socket_base { int rc = zmq_getsockopt(_handle, option_, optval_, optvallen_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } template @@ -1880,13 +1908,20 @@ class socket_base } #endif - void bind(std::string const &addr) { bind(addr.c_str()); } + NO_THROW_RETURN_TYPE(bool) bind(std::string const &addr) + { +#ifdef CPPZMQ_NO_CPP_EXCEPTIONS + return +#endif + bind(addr.c_str()); + } - void bind(const char *addr_) + NO_THROW_RETURN_TYPE(bool) bind(const char *addr_) { int rc = zmq_bind(_handle, addr_); if (rc != 0) - throw error_t(); + THROW_RETURN(false); + NO_THROW_RETURN(true); } void unbind(std::string const &addr) { unbind(addr.c_str()); } @@ -1895,16 +1930,23 @@ class socket_base { int rc = zmq_unbind(_handle, addr_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } - void connect(std::string const &addr) { connect(addr.c_str()); } + NO_THROW_RETURN_TYPE(bool) connect(std::string const &addr) + { +#ifdef CPPZMQ_NO_CPP_EXCEPTIONS + return +#endif + connect(addr.c_str()); + } - void connect(const char *addr_) + NO_THROW_RETURN_TYPE(bool) connect(const char *addr_) { int rc = zmq_connect(_handle, addr_); if (rc != 0) - throw error_t(); + THROW_RETURN(false); + NO_THROW_RETURN(true); } void disconnect(std::string const &addr) { disconnect(addr.c_str()); } @@ -1913,7 +1955,7 @@ class socket_base { int rc = zmq_disconnect(_handle, addr_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } ZMQ_DEPRECATED("from 4.7.1, use handle() != nullptr or operator bool") @@ -1927,7 +1969,7 @@ class socket_base return static_cast(nbytes); if (zmq_errno() == EAGAIN) return 0; - throw error_t(); + THROW_ERROR_T; } ZMQ_CPP11_DEPRECATED("from 4.3.1, use send taking message_t and send_flags") @@ -1939,7 +1981,7 @@ class socket_base return true; if (zmq_errno() == EAGAIN) return false; - throw error_t(); + THROW_ERROR_T; } template @@ -1954,7 +1996,7 @@ class socket_base return true; if (zmq_errno() == EAGAIN) return false; - throw error_t(); + THROW_ERROR_T; } #ifdef ZMQ_HAS_RVALUE_REFS @@ -1979,7 +2021,7 @@ class socket_base return static_cast(nbytes); if (zmq_errno() == EAGAIN) return {}; - throw error_t(); + THROW_ERROR_T; } send_result_t send(message_t &msg, send_flags flags) @@ -1989,7 +2031,7 @@ class socket_base return static_cast(nbytes); if (zmq_errno() == EAGAIN) return {}; - throw error_t(); + THROW_ERROR_T; } send_result_t send(message_t &&msg, send_flags flags) @@ -2007,7 +2049,7 @@ class socket_base return static_cast(nbytes); if (zmq_errno() == EAGAIN) return 0; - throw error_t(); + THROW_ERROR_T; } ZMQ_CPP11_DEPRECATED( @@ -2019,7 +2061,7 @@ class socket_base return true; if (zmq_errno() == EAGAIN) return false; - throw error_t(); + THROW_ERROR_T; } #ifdef ZMQ_CPP11 @@ -2036,7 +2078,7 @@ class socket_base } if (zmq_errno() == EAGAIN) return {}; - throw error_t(); + THROW_ERROR_T; } ZMQ_NODISCARD @@ -2050,7 +2092,7 @@ class socket_base } if (zmq_errno() == EAGAIN) return {}; - throw error_t(); + THROW_ERROR_T; } #endif @@ -2059,14 +2101,14 @@ class socket_base { int rc = zmq_join(_handle, group); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } void leave(const char *group) { int rc = zmq_leave(_handle, group); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } #endif @@ -2086,14 +2128,14 @@ class socket_base { int rc = zmq_setsockopt(_handle, option_, optval_, optvallen_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } void get_option(int option_, void *optval_, size_t *optvallen_) const { int rc = zmq_getsockopt(_handle, option_, optval_, optvallen_); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } }; } // namespace detail @@ -2143,27 +2185,33 @@ inline bool operator!=(std::nullptr_t /*p*/, socket_ref sr) ZMQ_NOTHROW } #endif -inline bool operator==(const detail::socket_base& a, const detail::socket_base& b) ZMQ_NOTHROW +inline bool operator==(const detail::socket_base &a, + const detail::socket_base &b) ZMQ_NOTHROW { return std::equal_to()(a.handle(), b.handle()); } -inline bool operator!=(const detail::socket_base& a, const detail::socket_base& b) ZMQ_NOTHROW +inline bool operator!=(const detail::socket_base &a, + const detail::socket_base &b) ZMQ_NOTHROW { return !(a == b); } -inline bool operator<(const detail::socket_base& a, const detail::socket_base& b) ZMQ_NOTHROW +inline bool operator<(const detail::socket_base &a, + const detail::socket_base &b) ZMQ_NOTHROW { return std::less()(a.handle(), b.handle()); } -inline bool operator>(const detail::socket_base& a, const detail::socket_base& b) ZMQ_NOTHROW +inline bool operator>(const detail::socket_base &a, + const detail::socket_base &b) ZMQ_NOTHROW { return b < a; } -inline bool operator<=(const detail::socket_base& a, const detail::socket_base& b) ZMQ_NOTHROW +inline bool operator<=(const detail::socket_base &a, + const detail::socket_base &b) ZMQ_NOTHROW { return !(a > b); } -inline bool operator>=(const detail::socket_base& a, const detail::socket_base& b) ZMQ_NOTHROW +inline bool operator>=(const detail::socket_base &a, + const detail::socket_base &b) ZMQ_NOTHROW { return !(a < b); } @@ -2197,7 +2245,7 @@ class socket_t : public detail::socket_base ctxptr(context_.handle()) { if (_handle == ZMQ_NULLPTR) - throw error_t(); + THROW_ERROR_T; } #ifdef ZMQ_CPP11 @@ -2259,9 +2307,9 @@ class socket_t : public detail::socket_base detail::socket_base(zmq_socket(context_, type_)), ctxptr(context_) { if (_handle == ZMQ_NULLPTR) - throw error_t(); + THROW_ERROR_T; if (ctxptr == ZMQ_NULLPTR) - throw error_t(); + THROW_ERROR_T; } }; @@ -2275,7 +2323,7 @@ inline void proxy(void *frontend, void *backend, void *capture) { int rc = zmq_proxy(frontend, backend, capture); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } inline void @@ -2283,7 +2331,7 @@ proxy(socket_ref frontend, socket_ref backend, socket_ref capture = socket_ref() { int rc = zmq_proxy(frontend.handle(), backend.handle(), capture.handle()); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } #ifdef ZMQ_HAS_PROXY_STEERABLE @@ -2293,7 +2341,7 @@ proxy_steerable(void *frontend, void *backend, void *capture, void *control) { int rc = zmq_proxy_steerable(frontend, backend, capture, control); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } inline void proxy_steerable(socket_ref frontend, @@ -2304,7 +2352,7 @@ inline void proxy_steerable(socket_ref frontend, int rc = zmq_proxy_steerable(frontend.handle(), backend.handle(), capture.handle(), control.handle()); if (rc != 0) - throw error_t(); + THROW_ERROR_T; } #endif @@ -2356,7 +2404,7 @@ class monitor_t { int rc = zmq_socket_monitor(socket.handle(), addr_, events); if (rc != 0) - throw error_t(); + THROW_ERROR_T; _socket = socket; _monitor_socket = socket_t(socket.ctxptr, ZMQ_PAIR); @@ -2373,11 +2421,11 @@ class monitor_t {_monitor_socket.handle(), 0, ZMQ_POLLIN, 0}, }; - #ifdef ZMQ_CPP11 +#ifdef ZMQ_CPP11 zmq::poll(&items[0], 1, std::chrono::milliseconds(timeout)); - #else +#else zmq::poll(&items[0], 1, timeout); - #endif +#endif return process_event(items[0].revents); } @@ -2664,7 +2712,7 @@ template class poller_t poller_t() : poller_ptr(zmq_poller_new()) { if (!poller_ptr) - throw error_t(); + THROW_ERROR_T; } template< @@ -2695,14 +2743,14 @@ template class poller_t void remove(zmq::socket_ref socket) { if (0 != zmq_poller_remove(poller_ptr.get(), socket.handle())) { - throw error_t(); + THROW_ERROR_T; } } void remove(fd_t fd) { if (0 != zmq_poller_remove_fd(poller_ptr.get(), fd)) { - throw error_t(); + THROW_ERROR_T; } } @@ -2711,7 +2759,7 @@ template class poller_t if (0 != zmq_poller_modify(poller_ptr.get(), socket.handle(), static_cast(events))) { - throw error_t(); + THROW_ERROR_T; } } @@ -2720,7 +2768,7 @@ template class poller_t if (0 != zmq_poller_modify_fd(poller_ptr.get(), fd, static_cast(events))) { - throw error_t(); + THROW_ERROR_T; } } @@ -2745,7 +2793,7 @@ template class poller_t #endif return 0; - throw error_t(); + THROW_ERROR_T; } #if ZMQ_VERSION >= ZMQ_MAKE_VERSION(4, 3, 3) @@ -2774,7 +2822,7 @@ template class poller_t if (0 != zmq_poller_add(poller_ptr.get(), socket.handle(), user_data, static_cast(events))) { - throw error_t(); + THROW_ERROR_T; } } @@ -2783,7 +2831,7 @@ template class poller_t if (0 != zmq_poller_add_fd(poller_ptr.get(), fd, user_data, static_cast(events))) { - throw error_t(); + THROW_ERROR_T; } } }; @@ -2811,7 +2859,7 @@ class timers timers() : _timers(zmq_timers_new()) { if (_timers == nullptr) - throw error_t(); + THROW_ERROR_T; } timers(const timers &other) = delete; @@ -2827,7 +2875,7 @@ class timers { id_t timer_id = zmq_timers_add(_timers, interval.count(), handler, arg); if (timer_id == -1) - throw zmq::error_t(); + THROW_ZMQ_ERROR_T; return timer_id; } @@ -2835,21 +2883,21 @@ class timers { int rc = zmq_timers_cancel(_timers, timer_id); if (rc == -1) - throw zmq::error_t(); + THROW_ZMQ_ERROR_T; } void set_interval(id_t timer_id, std::chrono::milliseconds interval) { int rc = zmq_timers_set_interval(_timers, timer_id, interval.count()); if (rc == -1) - throw zmq::error_t(); + THROW_ZMQ_ERROR_T; } void reset(id_t timer_id) { int rc = zmq_timers_reset(_timers, timer_id); if (rc == -1) - throw zmq::error_t(); + THROW_ZMQ_ERROR_T; } timeout_result_t timeout() const @@ -2864,7 +2912,7 @@ class timers { int rc = zmq_timers_execute(_timers); if (rc == -1) - throw zmq::error_t(); + THROW_ZMQ_ERROR_T; } private: diff --git a/zmq_addon.hpp b/zmq_addon.hpp index c6b4462..8f4d0f3 100644 --- a/zmq_addon.hpp +++ b/zmq_addon.hpp @@ -56,7 +56,7 @@ namespace zmq poller_ref_t(zmq::fd_t fd) : data{RT_FD, {}, fd} {} - size_t hash() const ZMQ_NOTHROW + size_t hash() const ZMQ_NOTHROW { std::size_t h = 0; hash_combine(h, std::get<0>(data)); @@ -94,6 +94,14 @@ template <> struct std::hash }; #endif // ZMQ_CPP11 +/* +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS +throw std::exception(); +#else +std::abort(); +#endif +*/ + namespace zmq { #ifdef ZMQ_CPP11 @@ -109,8 +117,12 @@ recv_multipart_n(socket_ref s, OutputIt out, size_t n, recv_flags flags) while (true) { if ZMQ_CONSTEXPR_IF (CheckN) { if (msg_count >= n) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::runtime_error( "Too many message parts in recv_multipart_n"); +#else + std::abort(); +#endif } if (!s.recv(msg, flags)) { // zmq ensures atomic delivery of messages @@ -161,11 +173,11 @@ inline uint32_t read_u32_network_order(const unsigned char *buf) } // namespace detail /* Receive a multipart message. - + Writes the zmq::message_t objects to OutputIterator out. The out iterator must handle an unspecified number of writes, e.g. by using std::back_inserter. - + Returns: the number of messages received or nullopt (on EAGAIN). Throws: if recv throws. Any exceptions thrown by the out iterator will be propagated and the message @@ -181,11 +193,11 @@ ZMQ_NODISCARD recv_result_t recv_multipart(socket_ref s, } /* Receive a multipart message. - + Writes at most n zmq::message_t objects to OutputIterator out. If the number of message parts of the incoming message exceeds n then an exception will be thrown. - + Returns: the number of messages received or nullopt (on EAGAIN). Throws: if recv throws. Throws std::runtime_error if the number of message parts exceeds n (exactly n messages will have been written @@ -204,12 +216,12 @@ ZMQ_NODISCARD recv_result_t recv_multipart_n(socket_ref s, } /* Send a multipart message. - + The range must be a ForwardRange of zmq::message_t, zmq::const_buffer or zmq::mutable_buffer. - The flags may be zmq::send_flags::sndmore if there are + The flags may be zmq::send_flags::sndmore if there are more message parts to be sent after the call to this function. - + Returns: the number of messages sent (exactly msgs.size()) or nullopt (on EAGAIN). Throws: if send throws. Any exceptions thrown by the msgs range will be propagated and the message @@ -283,8 +295,12 @@ message_t encode(const Range &parts) for (const auto &part : parts) { const size_t part_size = part.size(); if (part_size > (std::numeric_limits::max)()) { +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS // Size value must fit into uint32_t. throw std::range_error("Invalid size, message part too large"); +#else + std::abort(); +#endif } const size_t count_size = part_size < (std::numeric_limits::max)() ? 1 : 5; @@ -339,8 +355,12 @@ template OutputIt decode(const message_t &encoded, OutputIt out) size_t part_size = *source++; if (part_size == (std::numeric_limits::max)()) { if (static_cast(limit - source) < sizeof(uint32_t)) { +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::out_of_range( "Malformed encoding, overflow in reading size"); +#else + std::abort(); +#endif } part_size = detail::read_u32_network_order(source); // the part size is allowed to be less than 0xFF @@ -348,7 +368,11 @@ template OutputIt decode(const message_t &encoded, OutputIt out) } if (static_cast(limit - source) < part_size) { +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::out_of_range("Malformed encoding, overflow in reading part"); +#else + std::abort(); +#endif } *out = message_t(source, part_size); ++out; @@ -568,8 +592,12 @@ class multipart_t static_assert(!std::is_same::value, "Use popstr() instead of poptyp()"); if (sizeof(T) != m_parts.front().size()) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::runtime_error( "Invalid type, size does not match the message size"); +#else + std::abort(); +#endif T type = *m_parts.front().data(); m_parts.pop_front(); return type; @@ -613,8 +641,12 @@ class multipart_t static_assert(!std::is_same::value, "Use peekstr() instead of peektyp()"); if (sizeof(T) != m_parts[index].size()) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::runtime_error( "Invalid type, size does not match the message size"); +#else + std::abort(); +#endif T type = *m_parts[index].data(); return type; } @@ -744,11 +776,20 @@ class active_poller_t const poller_ref_t ref{socket}; if (!handler) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::invalid_argument("null handler in active_poller_t::add (socket)"); +#else + std::abort(); +#endif auto ret = handlers.emplace( ref, std::make_shared(std::move(handler))); if (!ret.second) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw error_t(EINVAL); // already added +#else + std::abort(); +#endif +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS try { base_poller.add(socket, events, ret.first->second.get()); need_rebuild = true; @@ -758,6 +799,10 @@ class active_poller_t handlers.erase(ref); throw; } +#else + base_poller.add(socket, events, ret.first->second.get()); + need_rebuild = true; +#endif } void add(fd_t fd, event_flags events, handler_type handler) @@ -765,11 +810,20 @@ class active_poller_t const poller_ref_t ref{fd}; if (!handler) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw std::invalid_argument("null handler in active_poller_t::add (fd)"); +#else + std::abort(); +#endif auto ret = handlers.emplace( ref, std::make_shared(std::move(handler))); if (!ret.second) +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS throw error_t(EINVAL); // already added +#else + std::abort(); +#endif +#ifndef CPPZMQ_NO_CPP_EXCEPTIONS try { base_poller.add(fd, events, ret.first->second.get()); need_rebuild = true; @@ -779,6 +833,10 @@ class active_poller_t handlers.erase(ref); throw; } +#else + base_poller.add(fd, events, ret.first->second.get()); + need_rebuild = true; +#endif } void remove(zmq::socket_ref socket)