mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-06-26 14:34:04 +02:00
Problem: throw error_t should follow only zmq call.
This commit is contained in:
parent
810b87c021
commit
f5b9fcc4ef
17
zmq.hpp
17
zmq.hpp
@ -1058,18 +1058,17 @@ namespace zmq
|
|||||||
|
|
||||||
void add (zmq::socket_t &socket, short events, handler_t handler)
|
void add (zmq::socket_t &socket, short events, handler_t handler)
|
||||||
{
|
{
|
||||||
if (!socket)
|
auto it = std::end (handlers);
|
||||||
throw error_t ();
|
auto inserted = false;
|
||||||
handler_t *handler_ptr = nullptr;
|
if (handler)
|
||||||
/// \todo is it sensible to allow handler to be empty? doesn't this lead to an error when the event is signalled? (perhaps it should already lead to an error in zmq_poller_add then)
|
std::tie(it, inserted) = handlers.emplace (socket.ptr, std::move (handler));
|
||||||
if (handler) {
|
if (0 == zmq_poller_add (poller_ptr, socket.ptr, inserted ? &(it->second) : nullptr, events)) {
|
||||||
auto emplace_res = handlers.emplace (socket.ptr, std::move (handler));
|
|
||||||
handler_ptr = &emplace_res.first->second;
|
|
||||||
}
|
|
||||||
if (0 == zmq_poller_add (poller_ptr, socket.ptr, handler_ptr, events)) {
|
|
||||||
poller_events.emplace_back (zmq_poller_event_t ());
|
poller_events.emplace_back (zmq_poller_event_t ());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// rollback
|
||||||
|
if (inserted)
|
||||||
|
handlers.erase (socket.ptr);
|
||||||
throw error_t ();
|
throw error_t ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user