summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-09-19 22:45:48 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-09-19 22:45:48 +0200
commit1d2399720b3fd06da5e7f9f4a211f30c57a9ce2d (patch)
tree291de88632b3047feab67b0a14ca48996d9ef86d
parentcda3c96a7fed0ee603c13e787ac511a1ea171367 (diff)
zmq_init_t destroyed zmq_engine_t before plugging it out from the poller first -- fixed
-rw-r--r--src/zmq_engine.cpp10
-rw-r--r--src/zmq_engine.hpp7
-rw-r--r--src/zmq_init.cpp2
3 files changed, 16 insertions, 3 deletions
diff --git a/src/zmq_engine.cpp b/src/zmq_engine.cpp
index 3e98c53..815697c 100644
--- a/src/zmq_engine.cpp
+++ b/src/zmq_engine.cpp
@@ -40,7 +40,8 @@ zmq::zmq_engine_t::zmq_engine_t (fd_t fd_, const options_t &options_) :
outsize (0),
encoder (out_batch_size),
inout (NULL),
- options (options_)
+ options (options_),
+ plugged (false)
{
// Initialise the underlying socket.
int rc = tcp_socket.open (fd_, options.sndbuf, options.rcvbuf);
@@ -49,10 +50,14 @@ zmq::zmq_engine_t::zmq_engine_t (fd_t fd_, const options_t &options_) :
zmq::zmq_engine_t::~zmq_engine_t ()
{
+ zmq_assert (!plugged);
}
void zmq::zmq_engine_t::plug (io_thread_t *io_thread_, i_inout *inout_)
{
+ zmq_assert (!plugged);
+ plugged = true;
+
// Conncet to session/init object.
zmq_assert (!inout);
zmq_assert (inout_);
@@ -72,6 +77,9 @@ void zmq::zmq_engine_t::plug (io_thread_t *io_thread_, i_inout *inout_)
void zmq::zmq_engine_t::unplug ()
{
+ zmq_assert (plugged);
+ plugged = false;
+
// Cancel all fd subscriptions.
rm_fd (handle);
diff --git a/src/zmq_engine.hpp b/src/zmq_engine.hpp
index bdd2a5d..363eaaf 100644
--- a/src/zmq_engine.hpp
+++ b/src/zmq_engine.hpp
@@ -39,7 +39,6 @@ namespace zmq
public:
zmq_engine_t (fd_t fd_, const options_t &options_);
- ~zmq_engine_t ();
// i_engine interface implementation.
void plug (class io_thread_t *io_thread_, struct i_inout *inout_);
@@ -54,6 +53,10 @@ namespace zmq
private:
+ // Destructor is not to be used directly.
+ // Use 'terminate' function instead.
+ ~zmq_engine_t ();
+
// Function to handle network disconnections.
void error ();
@@ -72,6 +75,8 @@ namespace zmq
options_t options;
+ bool plugged;
+
zmq_engine_t (const zmq_engine_t&);
void operator = (const zmq_engine_t&);
};
diff --git a/src/zmq_init.cpp b/src/zmq_init.cpp
index ee5741a..ba9706c 100644
--- a/src/zmq_init.cpp
+++ b/src/zmq_init.cpp
@@ -49,7 +49,7 @@ zmq::zmq_init_t::zmq_init_t (io_thread_t *io_thread_,
zmq::zmq_init_t::~zmq_init_t ()
{
if (engine)
- delete engine;
+ engine->terminate ();
}
bool zmq::zmq_init_t::read (::zmq_msg_t *msg_)