2010-08-11 14:09:56 +02:00
|
|
|
/*
|
2011-03-02 16:30:40 +01:00
|
|
|
Copyright (c) 2007-2011 iMatix Corporation
|
|
|
|
Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file
|
2010-08-11 14:09:56 +02:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
2010-10-30 15:08:28 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by
|
2010-08-11 14:09:56 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2010-10-30 15:08:28 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2010-08-11 14:09:56 +02:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2010-08-11 14:09:56 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "named_session.hpp"
|
|
|
|
#include "socket_base.hpp"
|
|
|
|
|
|
|
|
zmq::named_session_t::named_session_t (class io_thread_t *io_thread_,
|
|
|
|
socket_base_t *socket_, const options_t &options_,
|
2011-03-15 13:11:20 +01:00
|
|
|
const blob_t &peer_identity_) :
|
2010-08-11 14:09:56 +02:00
|
|
|
session_t (io_thread_, socket_, options_),
|
2011-03-15 13:11:20 +01:00
|
|
|
peer_identity (peer_identity_)
|
2010-08-11 14:09:56 +02:00
|
|
|
{
|
2011-03-15 13:11:20 +01:00
|
|
|
// Make double sure that the peer's identity is not transient.
|
|
|
|
zmq_assert (!peer_identity.empty ());
|
|
|
|
zmq_assert (peer_identity [0] != 0);
|
2010-08-11 14:09:56 +02:00
|
|
|
|
2011-03-15 13:11:20 +01:00
|
|
|
bool ok = socket_->register_session (peer_identity, this);
|
2010-08-11 14:09:56 +02:00
|
|
|
|
2011-03-15 13:11:20 +01:00
|
|
|
// 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);
|
2010-08-11 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
zmq::named_session_t::~named_session_t ()
|
|
|
|
{
|
2010-10-13 10:09:46 +02:00
|
|
|
// Unregister the session from the global list of named sessions.
|
2011-03-15 13:11:20 +01:00
|
|
|
unregister_session (peer_identity);
|
2010-08-11 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
2011-03-16 13:26:23 +01:00
|
|
|
bool zmq::named_session_t::attached (const blob_t &peer_identity_)
|
2010-08-11 14:09:56 +02:00
|
|
|
{
|
2011-03-16 13:26:23 +01:00
|
|
|
// Double check that identities match.
|
2011-03-15 13:11:20 +01:00
|
|
|
zmq_assert (peer_identity == peer_identity_);
|
2011-03-16 13:26:23 +01:00
|
|
|
|
|
|
|
// If the session already has an engine attached, destroy new one.
|
|
|
|
if (has_engine ()) {
|
|
|
|
log ("DPID: duplicate peer identity - disconnecting peer");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2010-08-11 14:09:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void zmq::named_session_t::detached ()
|
|
|
|
{
|
2011-03-15 13:11:20 +01:00
|
|
|
// Do nothing. Named sessions are never destroyed because of disconnection.
|
|
|
|
// Neither they have to actively reconnect.
|
2010-08-11 14:09:56 +02:00
|
|
|
}
|
2010-08-24 11:19:22 +02:00
|
|
|
|