mirror of
https://github.com/zeromq/cppzmq.git
synced 2025-10-23 00:08:02 +02:00
Problem: shutdown() missing for context_t (#377)
Solution: Add shutdown(). This function is required for clean termination of the zmq context in multi-threaded applications where sockets are used in threads. In particular if blocking operation are used and if sockets can be created at any time. * Improve tests and documentation
This commit is contained in:

committed by
Simon Giesecke

parent
70d059bd0a
commit
47969cfdcf
12
zmq.hpp
12
zmq.hpp
@@ -677,6 +677,7 @@ class context_t
|
||||
|
||||
~context_t() ZMQ_NOTHROW { close(); }
|
||||
|
||||
// Terminates context (see also shutdown()).
|
||||
void close() ZMQ_NOTHROW
|
||||
{
|
||||
if (ptr == ZMQ_NULLPTR)
|
||||
@@ -691,6 +692,17 @@ class context_t
|
||||
ptr = ZMQ_NULLPTR;
|
||||
}
|
||||
|
||||
// Shutdown context in preparation for termination (close()).
|
||||
// Causes all blocking socket operations and any further
|
||||
// socket operations to return with ETERM.
|
||||
void shutdown() ZMQ_NOTHROW
|
||||
{
|
||||
if (ptr == ZMQ_NULLPTR)
|
||||
return;
|
||||
int rc = zmq_ctx_shutdown(ptr);
|
||||
ZMQ_ASSERT(rc == 0);
|
||||
}
|
||||
|
||||
// Be careful with this, it's probably only useful for
|
||||
// using the C api together with an existing C++ api.
|
||||
// Normally you should never need to use this.
|
||||
|
Reference in New Issue
Block a user