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

bool DirectConnectionPool::addConnection ( DirectConnectionBase connection,
const QString &  ipAddress,
const quint16  port 
)

Add a connection to the list, tells the object to connect to the given ipaddress/port. Returns true when the connection could be added to the pending list (e.g. it's openConnection() method didn't fail).

Definition at line 68 of file directconnectionpool.cpp.

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

Referenced by ApplicationList::addConnection().

{
  // Refuse if there is already an active connection
  if( activeConnection_ != 0 )
  {
    kWarning() << "Refusing connection attempt, a connection has already been made.";
    return 0;
  }

#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
  kDebug() << "Adding new client connection to peer "
            << ipAddress << ":" << port << 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() ) );

  // Connect the the host
  bool opened = connection->openConnection( ipAddress, port );
  if( ! opened )
  {
    pendingConnections_.removeAll( connection );
    connection->deleteLater();

#ifdef KMESSDEBUG_DIRECTCONNECTION_GENERAL
    kDebug() << "Could not connect to " << ipAddress << ":" << port;
#endif
    return false;
  }

  return true;
}


Generated by  Doxygen 1.6.0   Back to index