Esempio n. 1
0
void ConnectionSet::addConnection( ConnectionPtr connection )
{
    LBASSERT( connection->isConnected() || connection->isListening( ));

    {
        lunchbox::ScopedWrite mutex( _impl->lock );
        _impl->allConnections.push_back( connection );

#ifdef _WIN32
        LBASSERT( _impl->allConnections.size() <
                  MAX_CONNECTIONS * MAX_CONNECTIONS );
        if ( !_isThreadMode && _impl->connections.size() < MAX_CONNECTIONS )
        {
            _impl->connections.push_back( connection );
        }
        else 
        {
            _addConnectionToThread( connection );
        } 
#else
        connection->addListener( _impl );

        LBASSERT( _impl->allConnections.size() < MAX_CONNECTIONS );
#endif // _WIN32
    }

    setDirty();
}
Esempio n. 2
0
void ConnectionSet::addConnection( ConnectionPtr connection )
{
    LBASSERT( connection->isConnected() || connection->isListening( ));

    { 
        lunchbox::ScopedWrite mutex( _impl->lock );
        _impl->allConnections.push_back( connection );

#ifdef _WIN32
        LBASSERT( _impl->allConnections.size() <
                  MAX_CONNECTIONS * MAX_CONNECTIONS );
        if( _impl->connections.size() < MAX_CONNECTIONS - _impl->threads.size())
        {
            // can handle it ourself
            _impl->connections.push_back( connection );
            connection->addListener( this );
        }
        else
        {
            // add to existing thread
            for( ThreadsCIter i = _impl->threads.begin();
                 i != _impl->threads.end(); ++i )
            {
                Thread* thread = *i;
                if( thread->set->getSize() > MAX_CONNECTIONS )
                    continue;

                thread->set->addConnection( connection );
                return;
            }

            // add to new thread
            Thread* thread = new Thread( this );
            thread->set->addConnection( connection );
            thread->set->addConnection( _impl->connections.back( ));
            _impl->connections.pop_back();

            _impl->threads.push_back( thread );
            thread->start();
        }
#else
        _impl->connections.push_back( connection );
        connection->addListener( this );

        LBASSERT( _impl->connections.size() < MAX_CONNECTIONS );
#endif // _WIN32
    }

    setDirty();
}
Esempio n. 3
0
void LocalNode::addListener( ConnectionPtr connection )
{
    EQASSERT( isListening( ));
    EQASSERT( connection->isListening( ));

    connection->ref( CO_REFERENCED_PARAM );
    NodeAddListenerPacket packet( connection );
    Nodes nodes;
    getNodes( nodes );

    for( Nodes::iterator i = nodes.begin(); i != nodes.end(); ++i )
    {
        (*i)->send( packet, connection->getDescription()->toString( ));
    }
}
Esempio n. 4
0
uint32_t LocalNode::removeListenerNB( ConnectionPtr connection )
{
    EQASSERT( isListening( ));
    EQASSERT( connection->isListening( ));

    connection->ref( CO_REFERENCED_PARAM );
    NodeRemoveListenerPacket packet( connection, registerRequest( ));
    Nodes nodes;
    getNodes( nodes );

    for( Nodes::iterator i = nodes.begin(); i != nodes.end(); ++i )
    {
        (*i)->send( packet, connection->getDescription()->toString( ));
    }
    return packet.requestID;
}