summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-10-13 10:09:46 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-10-13 10:09:46 +0200
commit9d96e0037a9d027fd286f771fa2a8db5def485c8 (patch)
tree8fe87b67d46182651a2fb54675ea102e220974f5
parent5ae878b891fa5189f5202f1577d22bdb9ba51f77 (diff)
Clean-up of the code related to attaching/detaching engines to sessions.
Session base class now handles the engine events exclusively. It notifies derived session types using dedicated "attached" and "detached" events. Couple of bugs was fixed along the way. Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
-rw-r--r--src/connect_session.cpp9
-rw-r--r--src/connect_session.hpp3
-rw-r--r--src/named_session.cpp15
-rw-r--r--src/named_session.hpp5
-rw-r--r--src/session.cpp18
-rw-r--r--src/session.hpp12
-rw-r--r--src/transient_session.cpp4
-rw-r--r--src/transient_session.hpp3
8 files changed, 32 insertions, 37 deletions
diff --git a/src/connect_session.cpp b/src/connect_session.cpp
index 833b551..4d8e322 100644
--- a/src/connect_session.cpp
+++ b/src/connect_session.cpp
@@ -105,14 +105,13 @@ void zmq::connect_session_t::start_connecting ()
zmq_assert (false);
}
-void zmq::connect_session_t::detached ()
+void zmq::connect_session_t::attached (const blob_t &peer_identity_)
{
- // Clean up the mess left over by the failed connection.
- clean_pipes ();
+}
+void zmq::connect_session_t::detached ()
+{
// Reconnect.
start_connecting ();
-
- session_t::detached ();
}
diff --git a/src/connect_session.hpp b/src/connect_session.hpp
index 65037f8..11aa253 100644
--- a/src/connect_session.hpp
+++ b/src/connect_session.hpp
@@ -41,7 +41,8 @@ namespace zmq
private:
- // Hook into session's disconnection mechanism.
+ // Handlers for events from session base class.
+ void attached (const blob_t &peer_identity_);
void detached ();
// Start the connection process.
diff --git a/src/named_session.cpp b/src/named_session.cpp
index a430091..b6a3acf 100644
--- a/src/named_session.cpp
+++ b/src/named_session.cpp
@@ -41,14 +41,9 @@ zmq::named_session_t::named_session_t (class io_thread_t *io_thread_,
zmq::named_session_t::~named_session_t ()
{
-}
-
-void zmq::named_session_t::detach ()
-{
- // Clean up the mess left over by the failed connection.
- clean_pipes ();
-
- // Do nothing. Wait till the connection comes up again.
+ // Unregister the session from the global list of named sessions.
+ if (!name.empty ())
+ unregister_session (name);
}
void zmq::named_session_t::attached (const blob_t &peer_identity_)
@@ -83,7 +78,7 @@ void zmq::named_session_t::attached (const blob_t &peer_identity_)
void zmq::named_session_t::detached ()
{
- unregister_session (name);
- session_t::detached ();
+ // Do nothing. Named sessions are never destroyed because of disconnection,
+ // neither they have to actively reconnect.
}
diff --git a/src/named_session.hpp b/src/named_session.hpp
index 335b4a9..9c8f814 100644
--- a/src/named_session.hpp
+++ b/src/named_session.hpp
@@ -38,10 +38,7 @@ namespace zmq
const blob_t &name_);
~named_session_t ();
- // i_inout interface implementation.
- void detach ();
-
- // Handle events from session_t base class.
+ // Handlers for events from session base class.
void attached (const blob_t &peer_identity_);
void detached ();
diff --git a/src/session.cpp b/src/session.cpp
index 76e782b..d5c6fdd 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -260,7 +260,15 @@ void zmq::session_t::detach ()
// Engine is dead. Let's forget about it.
engine = NULL;
+ // Remove any half-done messages from the pipes.
+ clean_pipes ();
+
+ // Send the event to the derived class.
detached ();
+
+ // Just in case, there's only a delimiter in the inbound pipe.
+ if (in_pipe)
+ in_pipe->check_read ();
}
void zmq::session_t::process_term ()
@@ -293,16 +301,6 @@ void zmq::session_t::unregister_session (const blob_t &name_)
socket->unregister_session (name_);
}
-void zmq::session_t::attached (const blob_t &peer_identity_)
-{
-}
-
-void zmq::session_t::detached ()
-{
- if (in_pipe)
- in_pipe->check_read ();
-}
-
void zmq::session_t::terminate ()
{
force_terminate = true;
diff --git a/src/session.hpp b/src/session.hpp
index 7e528de..0f90e80 100644
--- a/src/session.hpp
+++ b/src/session.hpp
@@ -70,8 +70,8 @@ namespace zmq
// when session is attached to a peer, detached is triggered at the
// beginning of the termination process when session is about to
// be detached from the peer.
- virtual void attached (const blob_t &peer_identity_);
- virtual void detached ();
+ virtual void attached (const blob_t &peer_identity_) = 0;
+ virtual void detached () = 0;
// Allows derives session types to (un)register session names.
bool register_session (const blob_t &name_, class session_t *session_);
@@ -79,10 +79,6 @@ namespace zmq
~session_t ();
- // Remove any half processed messages. Flush unflushed messages.
- // Call this function when engine disconnect to get rid of leftovers.
- void clean_pipes ();
-
// Inherited socket options. These are visible to all session classes.
options_t options;
@@ -94,6 +90,10 @@ namespace zmq
const blob_t &peer_identity_);
void process_term ();
+ // Remove any half processed messages. Flush unflushed messages.
+ // Call this function when engine disconnect to get rid of leftovers.
+ void clean_pipes ();
+
// Call this function to move on with the delayed process_term.
void proceed_with_term ();
diff --git a/src/transient_session.cpp b/src/transient_session.cpp
index 6711bc2..ff4b978 100644
--- a/src/transient_session.cpp
+++ b/src/transient_session.cpp
@@ -29,6 +29,10 @@ zmq::transient_session_t::~transient_session_t ()
{
}
+void zmq::transient_session_t::attached (const blob_t &peer_identity_)
+{
+}
+
void zmq::transient_session_t::detached ()
{
// There's no way to reestablish a transient session. Tear it down.
diff --git a/src/transient_session.hpp b/src/transient_session.hpp
index 2a7f3d5..d244982 100644
--- a/src/transient_session.hpp
+++ b/src/transient_session.hpp
@@ -38,7 +38,8 @@ namespace zmq
private:
- // Hook into session's disconnection mechanism.
+ // Handlers for events from session base class.
+ void attached (const blob_t &peer_identity_);
void detached ();
transient_session_t (const transient_session_t&);