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

void P2PApplication::slotSendData (  )  [private, slot]

A slot which sends the file data. This slot is called from a timer event.

Definition at line 2144 of file p2papplication.cpp.

References sendP2PMessage().

Referenced by sendData().

{
  // KMess would crash otherwise...
  if( dataSource_ == 0 )
  {
    kdDebug() << "P2PApplication: WARNING - Couldn't send more data, data source is null." << endl;

    // Don't send an error message, already happened before.
    return;
  }

  // Read the data from the file.
  char buffer[1202]; // 1202 is the max P2P data size.
  int bytesRead = dataSource_->readBlock( buffer, 1202 );

  QByteArray data;
  data.duplicate( buffer, bytesRead );

#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: sending data."
            << " offset = " << messageOffset_
            << " buffer = " << bytesRead
            << endl;
#endif


  // Determine the flags:
  // Funny, MSN6 didn't seam to care which flag was set
  // while transferring the file. KMess however, does.
  if( dataType_ == P2P_TYPE_PICTURE )
  {
    sendP2PMessage(data, P2PMessage::MSN_FLAG_DATA, 1);
  }
  else if( dataType_ == P2P_TYPE_FILE )
  {
    sendP2PMessage(data, P2PMessage::MSN_FLAG_FILETRANSFER, 2);
  }
  else
  {
    if(messageOffset_ == 0) kdDebug() << "P2PApplication: Unknown data transfer mode." << endl;
    sendP2PMessage(data, 0, 1); // The best solution in this situation
  }


  // Finished?
  if(messageTotalSize_ > 0)
  {
    // Run this slot again after 10 ms.
    QTimer::singleShot( 10, this, SLOT(slotSendData()) );
    return;
  }


  // Finished!
#ifdef KMESSTEST
  ASSERT( dataSource_->atEnd() );
#endif
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: Finished sending data, waiting for BYE message..." << endl;
#endif

  dataSource_   = 0;
  dataType_     = P2P_TYPE_NEGOTIATION;

  // We transmitted our file, the caller could
  // close the session now by sending a BYE message.


  waitingState_ = P2P_WAIT_FOR_SLP_BYE;
  waitingTimer_->start(30000, true); // 30 sec
}


Generated by  Doxygen 1.6.0   Back to index