From 32ded2b457b2102dba4c15e00363f031d212b1c4 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Wed, 16 Mar 2011 13:26:23 +0100 Subject: Duplicate identities now checked with zmq_connect Signed-off-by: Martin Sustrik --- src/session.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/session.cpp') diff --git a/src/session.cpp b/src/session.cpp index 33c25d9..3ba971f 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -214,26 +214,25 @@ void zmq::session_t::process_plug () void zmq::session_t::process_attach (i_engine *engine_, const blob_t &peer_identity_) { - // If some other object (e.g. init) notifies us that the connection failed - // we need to start the reconnection process. - if (!engine_) { - zmq_assert (!engine); - detached (); - return; - } - // If we are already terminating, we destroy the engine straight away. // Note that we don't have to unplug it before deleting as it's not // yet plugged to the session. if (state == terminating) { - delete engine_; + if (engine_) + delete engine_; return; } - // If the session already has an engine attached, destroy new one. - // Note new engine is not plugged in yet, we don't have to unplug it. - if (engine) { - log ("DPID: duplicate peer identity - disconnecting peer"); + // If some other object (e.g. init) notifies us that the connection failed + // without creating an engine we need to start the reconnection process. + if (!engine_) { + zmq_assert (!engine); + detached (); + return; + } + + // Trigger the notfication event about the attachment. + if (!attached (peer_identity_)) { delete engine_; return; } @@ -248,8 +247,8 @@ void zmq::session_t::process_attach (i_engine *engine_, // Create the pipes, as required. if (options.requires_in) { - create_pipe (socket, this, options.hwm, options.swap, &socket_reader, - &out_pipe); + create_pipe (socket, this, options.hwm, options.swap, + &socket_reader, &out_pipe); out_pipe->set_event_sink (this); } if (options.requires_out) { @@ -264,11 +263,9 @@ void zmq::session_t::process_attach (i_engine *engine_, } // Plug in the engine. + zmq_assert (!engine); engine = engine_; engine->plug (io_thread, this); - - // Trigger the notfication about the attachment. - attached (peer_identity_); } void zmq::session_t::detach () @@ -330,6 +327,11 @@ void zmq::session_t::timer_event (int id_) proceed_with_term (); } +bool zmq::session_t::has_engine () +{ + return engine != NULL; +} + bool zmq::session_t::register_session (const blob_t &name_, session_t *session_) { return socket->register_session (name_, session_); -- cgit v1.2.3