Ejemplo 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( _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();
}
Ejemplo 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 ( !_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();
}