Logo Search packages:      
Sourcecode: kmess version File versions  Download package

void DirectConnectionPool::slotConnectionEstablished (  )  [slot]

A direct connection is established.

Definition at line 317 of file directconnectionpool.cpp.

References clearPending(), DirectConnectionBase::getRemoteIp(), DirectConnectionBase::getRemotePort(), DirectConnectionBase::initialize(), and DirectConnectionBase::isConnected().

Referenced by addConnection(), and addServerConnection().

{
#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
  kdDebug() << "DirectConnectionPool::slotConnectionEstablished() - Direct connection established." << endl;
#endif

  // Test whether two connection attempts were established quickly after each other.
  if( activeConnection_ != 0 )
  {
#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
    kdDebug() << "DirectConnectionPool::slotConnectionEstablished() - Already got an active connection, removing other connections." << endl;
#endif
    clearPending();
    return;
  }

  // No connection yet, find the first successful connection.
  QPtrListIterator<DirectConnectionBase> it(pendingConnections_);
  while( it.current() != 0 )
  {
    DirectConnectionBase *pendingConnection = it.current();
    if( pendingConnection->isConnected() )
    {
      // Established connection found, remove from list.
      pendingConnections_.remove( pendingConnection );

      // Try to initialize the connection.
      bool success = pendingConnection->initialize();
      if( ! success )
      {
        // Not initialized (e.g. preamble cound not be sent in case of a MsnDirectConnection),
        // try the next item in the list instead.
#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
        kdDebug() << "DirectConnectionPool::slotConnectionEstablished() - could not initialize connection, "
                  << "trying next available connection." << endl;
#endif
        pendingConnection->deleteLater();
        pendingConnection = 0;
        continue;
      }
      else
      {
        // Initialized, this is the active connection!
        activeConnection_ = pendingConnection;
        break;
      }
    }

    ++it;
  }

  // If there is an initialized connection, remove all other pending connections.
  if( activeConnection_ != 0 )
  {
#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
    kdDebug() << "DirectConnectionPool::slotConnectionEstablished() - Connected to peer "
              << activeConnection_->getRemoteIp() << ":" << activeConnection_->getRemotePort() << endl;
#endif

    if( pendingConnections_.count() > 0 )
    {
      clearPending();
    }

    // Signal the connection is established, allows to sent any handshake, etc..
    emit connectionEstablished();
  }
}


Generated by  Doxygen 1.6.0   Back to index