Skip to content

Commit 7efc9b1

Browse files
authored
Merge pull request #432 from or17191/bugfix/socket-move-assignment-not-initializing-ctxptr
Bugfix: socket_t move assignment doesn't initialize ctxptr
2 parents 12c3003 + 37e6334 commit 7efc9b1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

tests/monitor.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,19 @@ TEST_CASE("monitor init abort", "[monitor]")
142142
monitor.abort();
143143
thread.join();
144144
}
145+
146+
147+
TEST_CASE("monitor from move assigned socket", "[monitor]")
148+
{
149+
zmq::context_t ctx;
150+
zmq::socket_t sock;
151+
sock = std::move([&ctx] {
152+
zmq::socket_t sock(ctx, ZMQ_DEALER);
153+
return sock;
154+
}());
155+
zmq::monitor_t monitor1;
156+
monitor1.init(sock, "inproc://monitor-client");
157+
// On failure, this test might hang indefinitely instead of immediately
158+
// failing
159+
}
145160
#endif

zmq.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,7 @@ class socket_t : public detail::socket_base
21032103
{
21042104
close();
21052105
std::swap(_handle, rhs._handle);
2106+
std::swap(ctxptr, rhs.ctxptr);
21062107
return *this;
21072108
}
21082109
#endif
@@ -2121,6 +2122,7 @@ class socket_t : public detail::socket_base
21212122
int rc = zmq_close(_handle);
21222123
ZMQ_ASSERT(rc == 0);
21232124
_handle = ZMQ_NULLPTR;
2125+
ctxptr = ZMQ_NULLPTR;
21242126
}
21252127

21262128
void swap(socket_t &other) ZMQ_NOTHROW
@@ -2143,6 +2145,9 @@ class socket_t : public detail::socket_base
21432145
{
21442146
if (_handle == ZMQ_NULLPTR)
21452147
throw error_t();
2148+
if (ctxptr == ZMQ_NULLPTR)
2149+
throw error_t();
2150+
21462151
}
21472152
};
21482153

0 commit comments

Comments
 (0)