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

int DirectConnectionPool::addServerConnection ( DirectConnectionBase connection  ) 

Add a connection to the list, starts listening for incoming connections.

Definition at line 114 of file directconnectionpool.cpp.

References DirectConnectionBase::getLocalServerPort(), DirectConnectionBase::openServerPort(), slotConnectionAuthorized(), slotConnectionClosed(), slotConnectionEstablished(), and slotConnectionFailed().

Referenced by ApplicationList::addServerConnection().

{
  // Refuse if there is already an active connection
  if( activeConnection_ != 0 )
  {
    kdWarning() << "DirectConnectionPool::addServerConnection() - Refusing server connection attempt, a connection has already been made." << endl;
    return 0;
  }

#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
  kdDebug() << "DirectConnectionPool::addServerConnection() - Adding new server connection to listen at port" << connection->getLocalServerPort() << endl;
#endif

  pendingConnections_.append( connection );  // append to pending list before signals are fired.

  // Connect it
  connect( connection, SIGNAL(     connectionEstablished() ) ,  // The connection was established
           this,         SLOT( slotConnectionEstablished() ) );
  connect( connection, SIGNAL(          connectionFailed() ) ,  // The connection could not be made
           this,         SLOT(      slotConnectionFailed() ) );
  connect( connection, SIGNAL(          connectionClosed() ) ,  // The connection was closed
           this,         SLOT(      slotConnectionClosed() ) );
  connect( connection, SIGNAL(      connectionAuthorized() ) ,  // The connection was authorized
           this,         SLOT(  slotConnectionAuthorized() ) );

  bool listening = false;

  // Attempt to listen at one of the 10 ports we use.
  for(int i = 0; i < 10; i++)
  {
    // The openServerPort() automatically picks another port
    // if the previous call failed.
    listening = connection->openServerPort();

    if(listening)
    {
      break;
    }
  }

  if( ! listening )
  {
    pendingConnections_.remove( connection );
    connection->deleteLater();

#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
    kdDebug() << "DirectConnectionPool::addServerConnection() - Could not find a port to listen at." << endl;
#endif
    return 0;
  }

  // Return port we're listening at.
  return connection->getLocalServerPort();
}


Generated by  Doxygen 1.6.0   Back to index