コード例 #1
0
ファイル: PConnection.cpp プロジェクト: binghuo365/BaseLab
PConnection *
PConnectionManager::create_connection (void)
{
    ACE_GUARD_RETURN (ACE_SYNCH_RECURSIVE_MUTEX, monitor, this->lock_, 0);

    if (this->num_connections_ >= MAX_CONNECTIONS ||
            this->flg_cancel_ != 0)
        return 0;

    PConnection * connection = 0;

    for (u_int i = 0; i < MAX_CONNECTIONS; ++i)
    {
        if (this->list_connections_[i] != 0)
            continue;

        connection = this->factory_.create_connection(*this);

        if (connection == 0)
            break;

        this->list_connections_[i] = connection;
        this->num_connections_++;

        if (this->num_connections_ > this->peak_connections_)
            this->peak_connections_ = this->num_connections_;

        connection->set_manager (this,i);
        connection->set_timeout (this->timeout_);

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%t) %s=%d NEW %s=%d\n"),
                    this->get_name(),
                    this->num_connections_,
                    connection->get_name(),
                    i));

        PConnectionProtocol * protocol =
            this->factory_.create_protocol (connection);

        connection->set_protocol (protocol);

        break;
    }

    return connection;
}
コード例 #2
0
ファイル: PConnection.cpp プロジェクト: binghuo365/BaseLab
void
PConnectionManager::destroy_connection(int index)
{
    ACE_GUARD (ACE_SYNCH_RECURSIVE_MUTEX, monitor, this->lock_);

    ACE_ASSERT(ACE_static_cast(u_int,index) < MAX_CONNECTIONS);

    PConnection * connection = this->list_connections_[index];

    if (!connection)
        return;

    this->total_snd_ += connection->get_total_snd();
    this->total_rcv_ += connection->get_total_rcv();
    this->total_w_   += connection->get_total_w();
    this->total_r_   += connection->get_total_r();

    this->factory_.destroy_protocol (connection->protocol ());
    connection->set_protocol (0);

    this->num_connections_--;
    this->list_connections_[index] = 0;


    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("(%t) %s=%d: DEL %s=%d S=%d(%d+%d) R=%d(%d+%d)\n"),
                this->get_name(),
                this->num_connections_,
                connection->get_name(),
                index,
                connection->get_total_snd(),
                connection->get_total_w(),
                connection->get_ref_cnt_w(),
                connection->get_total_rcv(),
                connection->get_total_r(),
                connection->get_ref_cnt_r()));

    connection->set_manager (0,-1);

    this->factory_.destroy_connection (connection) ;

    if (this->is_safe_to_delete())
        this->task().signal_main();
}