From 80ac398bba928fa7f245d2e107071677a13185cf Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 9 Feb 2011 15:32:15 +0100 Subject: Initial implementation of reaper thread. Reaper thread destroys the socket asynchronously. zmq_term() can be interrupted by a signal (EINTR). zmq_socket() will return ETERM after zmq_term() was called. Signed-off-by: Martin Sustrik --- src/socket_base.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/socket_base.cpp') diff --git a/src/socket_base.cpp b/src/socket_base.cpp index f19187f..0643d4d 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -570,13 +570,10 @@ int zmq::socket_base_t::recv (::zmq_msg_t *msg_, int flags_) int zmq::socket_base_t::close () { - // Start termination of associated I/O object hierarchy. - terminate (); - - // Ask context to zombify this socket. In other words, transfer - // the ownership of the socket from this application thread - // to the context which will take care of the rest of shutdown process. - zombify_socket (this); + // Transfer the ownership of the socket from this application thread + // to the reaper thread which will take care of the rest of shutdown + // process. + send_reap (this); return 0; } @@ -627,7 +624,7 @@ zmq::session_t *zmq::socket_base_t::find_session (const blob_t &name_) return session; } -bool zmq::socket_base_t::dezombify () +bool zmq::socket_base_t::reap () { // Process any commands from other threads/sockets that may be available // at the moment. Ultimately, socket will be destroyed. @@ -635,6 +632,11 @@ bool zmq::socket_base_t::dezombify () // If the object was already marked as destroyed, finish the deallocation. if (destroyed) { + + // Remove the socket from the context. + destroy_socket (this); + + // Deallocate. own_t::process_destroy (); return true; } -- cgit v1.2.3