Example #1
0
  ConnectionBase* ConnBoshMultStat::getConnection()
  {
    if( m_openRequests > 0 && m_openRequests >= m_maxOpenRequests )
    {
      m_logInstance.warn( LogAreaClassConnectionBOSH,
                          "Too many requests already open. Cannot send." );
      return 0;
    }

    ConnectionBase* conn = 0;
    switch( m_connMode )
    {
      case ModePipelining:
        if( !m_activeConnections.empty() )
        {
          m_logInstance.dbg( LogAreaClassConnectionBOSH, "Using default connection for Pipelining." );
          return m_activeConnections.front();
        }
        else if( !m_connectionPool.empty() )
        {
          m_logInstance.warn( LogAreaClassConnectionBOSH,
                              "Pipelining selected, but no connection open. Opening one." );
          return activateConnection();
        }
        else
          m_logInstance.warn( LogAreaClassConnectionBOSH,
                              "No available connections to pipeline on." );
        break;
      case ModeLegacyHTTP:
      case ModePersistentHTTP:
      {
        if( !m_connectionPool.empty() )
        {
          m_logInstance.dbg( LogAreaClassConnectionBOSH, "LegacyHTTP/PersistentHTTP selected, "
                                                         "using connection from pool." );
          return activateConnection();
        }
        else if( !m_activeConnections.empty() )
        {
          m_logInstance.dbg( LogAreaClassConnectionBOSH, "No connections in pool, creating a new one." );
          conn = m_activeConnections.front()->newInstance();
          conn->registerConnectionDataHandler( this );
          m_connectionPool.push_back( conn );
          conn->connect();
        }
        else
          m_logInstance.warn( LogAreaClassConnectionBOSH,
                              "No available connections to send on." );
        break;
      }
    }
    return 0;
  }
  ConnectionBase* SOCKS5BytestreamServer::getConnection( const std::string& hash )
  {
    util::MutexGuard mg( m_mutex );

    ConnectionMap::iterator it = m_connections.begin();
    for( ; it != m_connections.end(); ++it )
    {
      if( (*it).second.hash == hash )
      {
        ConnectionBase* conn = (*it).first;
        conn->registerConnectionDataHandler( 0 );
        m_connections.erase( it );
        return conn;
      }
    }

    return 0;
  }