You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem: poller_t invalid behaviour on invalid sockets
On adding invalid socket (e.g. after move) there was exception thrown
but leaving modified and unconsistent internal state.
Besides that there was no possibility to remove a socket that was moved
into.
Solutions: check for socket validity (added operator bool) and changed
internal unordered_map "handlers" to operator on zmq internal pointers.
Added two test cases covering the issues.
Copy file name to clipboardExpand all lines: zmq.hpp
+10-6Lines changed: 10 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -536,6 +536,11 @@ namespace zmq
536
536
{
537
537
return ptr;
538
538
}
539
+
540
+
inlineoperatorbool() const ZMQ_NOTHROW
541
+
{
542
+
return ptr != NULL;
543
+
}
539
544
private:
540
545
541
546
void *ptr;
@@ -1053,10 +1058,12 @@ namespace zmq
1053
1058
1054
1059
voidadd (zmq::socket_t &socket, short events, handler_t handler)
1055
1060
{
1061
+
if (!socket)
1062
+
throwerror_t ();
1056
1063
handler_t *handler_ptr = nullptr;
1057
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)
1058
1065
if (handler) {
1059
-
auto emplace_res = handlers.emplace(&socket, std::move(handler));
1066
+
auto emplace_res = handlers.emplace (socket.ptr, std::move(handler));
1060
1067
handler_ptr = &emplace_res.first->second;
1061
1068
}
1062
1069
if (0 == zmq_poller_add (poller_ptr, socket.ptr, handler_ptr, events)) {
@@ -1069,10 +1076,7 @@ namespace zmq
1069
1076
voidremove (zmq::socket_t &socket)
1070
1077
{
1071
1078
if (0 == zmq_poller_remove (poller_ptr, socket.ptr)) {
1072
-
auto it = handlers.find (&socket);
1073
-
if (it != handlers.end ()) { /// \todo this may only be false if handler was empty on add
0 commit comments