Skip to content

Commit f5b9fcc

Browse files
committed
Problem: throw error_t should follow only zmq call.
1 parent 810b87c commit f5b9fcc

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

zmq.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,18 +1058,17 @@ namespace zmq
10581058

10591059
void add (zmq::socket_t &socket, short events, handler_t handler)
10601060
{
1061-
if (!socket)
1062-
throw error_t ();
1063-
handler_t *handler_ptr = nullptr;
1064-
/// \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)
1065-
if (handler) {
1066-
auto emplace_res = handlers.emplace (socket.ptr, std::move (handler));
1067-
handler_ptr = &emplace_res.first->second;
1068-
}
1069-
if (0 == zmq_poller_add (poller_ptr, socket.ptr, handler_ptr, events)) {
1061+
auto it = std::end (handlers);
1062+
auto inserted = false;
1063+
if (handler)
1064+
std::tie(it, inserted) = handlers.emplace (socket.ptr, std::move (handler));
1065+
if (0 == zmq_poller_add (poller_ptr, socket.ptr, inserted ? &(it->second) : nullptr, events)) {
10701066
poller_events.emplace_back (zmq_poller_event_t ());
10711067
return;
10721068
}
1069+
// rollback
1070+
if (inserted)
1071+
handlers.erase (socket.ptr);
10731072
throw error_t ();
10741073
}
10751074

0 commit comments

Comments
 (0)