MulticastSession* MulticastTransport::start_session(const MulticastDataLink_rch& link, MulticastPeer remote_peer, bool active) { if (link.is_nil()) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ") ACE_TEXT("MulticastTransport[%C]::start_session: ") ACE_TEXT("link is nil\n"), this->config_i_->name().c_str()), 0); } MulticastSession_rch session = link->find_or_create_session(remote_peer); if (session.is_nil()) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ") ACE_TEXT("MulticastTransport[%C]::start_session: ") ACE_TEXT("failed to create session for remote peer: 0x%x!\n"), this->config_i_->name().c_str(), remote_peer), 0); } if (!session->start(active)) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ") ACE_TEXT("MulticastTransport[%C]::start_session: ") ACE_TEXT("failed to start session for remote peer: 0x%x!\n"), this->config_i_->name().c_str(), remote_peer), 0); } return session._retn(); }
MulticastSession* MulticastDataLink::find_or_create_session(MulticastPeer remote_peer) { ACE_GUARD_RETURN(ACE_SYNCH_RECURSIVE_MUTEX, guard, this->session_lock_, false); MulticastSessionMap::iterator it(this->sessions_.find(remote_peer)); if (it != this->sessions_.end()) return it->second.in(); // already exists MulticastSession_rch session = this->session_factory_->create(this, remote_peer); if (session.is_nil()) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ") ACE_TEXT("MulticastDataLink::find_or_create_session: ") ACE_TEXT("failed to create session for remote peer: 0x%x!\n"), remote_peer), false); } std::pair<MulticastSessionMap::iterator, bool> pair = this->sessions_.insert( MulticastSessionMap::value_type(remote_peer, session)); if (pair.first == this->sessions_.end()) { ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: ") ACE_TEXT("MulticastDataLink::find_or_create_session: ") ACE_TEXT("failed to insert session for remote peer: 0x%x!\n"), remote_peer), false); } return session._retn(); }