diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/named_session.cpp | 57 | ||||
-rw-r--r-- | src/named_session.hpp | 5 |
2 files changed, 18 insertions, 44 deletions
diff --git a/src/named_session.cpp b/src/named_session.cpp index 2532c5a..7e2c49e 100644 --- a/src/named_session.cpp +++ b/src/named_session.cpp @@ -23,63 +23,38 @@ zmq::named_session_t::named_session_t (class io_thread_t *io_thread_, socket_base_t *socket_, const options_t &options_, - const blob_t &name_) : + const blob_t &peer_identity_) : session_t (io_thread_, socket_, options_), - name (name_) + peer_identity (peer_identity_) { - // Make double sure that the session has valid name. - zmq_assert (!name.empty ()); - zmq_assert (name [0] != 0); + // Make double sure that the peer's identity is not transient. + zmq_assert (!peer_identity.empty ()); + zmq_assert (peer_identity [0] != 0); - if (!socket_->register_session (name, this)) { + bool ok = socket_->register_session (peer_identity, this); - // TODO: There's already a session with the specified - // identity. We should log the error and drop the - // session. - zmq_assert (false); - } + // If new session is being created, the caller should have already + // checked that the session for specified identity doesn't exist yet. + // Thus, register_session should not fail. + zmq_assert (ok); } zmq::named_session_t::~named_session_t () { // Unregister the session from the global list of named sessions. - if (!name.empty ()) - unregister_session (name); + unregister_session (peer_identity); } void zmq::named_session_t::attached (const blob_t &peer_identity_) { - if (!name.empty ()) { - - // If both IDs are temporary, no checking is needed. - // TODO: Old ID should be reused in this case... - if (name.empty () || name [0] != 0 || - peer_identity_.empty () || peer_identity_ [0] != 0) { - - // If we already know the peer name do nothing, just check whether - // it haven't changed. - zmq_assert (name == peer_identity_); - } - } - else if (!peer_identity_.empty ()) { - - // Store the peer identity. - name = peer_identity_; - - // Register the session using the peer name. - if (!register_session (name, this)) { - - // TODO: There's already a session with the specified - // identity. We should presumably syslog it and drop the - // session. - zmq_assert (false); - } - } + // The owner should take care to not attach the session + // to an unrelated peer. + zmq_assert (peer_identity == peer_identity_); } void zmq::named_session_t::detached () { - // Do nothing. Named sessions are never destroyed because of disconnection, - // neither they have to actively reconnect. + // 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 cf31209..fac4745 100644 --- a/src/named_session.hpp +++ b/src/named_session.hpp @@ -36,7 +36,7 @@ namespace zmq named_session_t (class io_thread_t *io_thread_, class socket_base_t *socket_, const options_t &options_, - const blob_t &name_); + const blob_t &peer_identity_); ~named_session_t (); // Handlers for events from session base class. @@ -45,8 +45,7 @@ namespace zmq private: - // Name of the session. Corresponds to the peer's strong identity. - blob_t name; + blob_t peer_identity; named_session_t (const named_session_t&); const named_session_t &operator = (const named_session_t&); |