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

void DirectConnectionPool::slotConnectionEstablished (  )  [slot]

A direct connection is established.

Definition at line 346 of file directconnectionpool.cpp.

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

Referenced by addConnection(), and addServerConnection().

{
#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
  kDebug() << "Direct connection established.";
#endif

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

  // No connection yet, find the first successful connection.
  foreach( DirectConnectionBase *pendingConnection, pendingConnections_ )
  {
    if( pendingConnection->isConnected() )
    {
#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
      kDebug() << "Connected to peer "
               << pendingConnection->getRemoteIp() << ":" << pendingConnection->getRemotePort() << endl;
#endif

      // Established connection found, remove from list.
      pendingConnections_.removeAll( 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
        kDebug() << "could not initialize connection, "
                    "trying next available connection." << endl;
#endif
        pendingConnection->deleteLater();
        pendingConnection = 0;
        continue;
      }
      else
      {
        // For webcam connections at port 80: wait until connection is authorized too.
        if( waitForAuthorized_ )
        {
#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
          kDebug() << "by request, waiting for the connection to authorize first...";
#endif

          unauthorizedConnections_.append( pendingConnection );
          return;
        }

        // Initiated, this is the active connection!
        activeConnection_ = pendingConnection;
        break;
      }
    }
  }

  // If there is an initialized connection, remove all other pending connections.
  if( activeConnection_ != 0 )
  {
    clearPending();

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


Generated by  Doxygen 1.6.0   Back to index