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

bool UdpDataProtocol::waitForReady ( QUdpSocket &  UdpSocket,
int  timeout_msec 
) [private]

This function blocks until data is available for reading in the QUdpSocket. The function will timeout after timeout_msec microseconds.

This function is intended to replace QAbstractSocket::waitForReadyRead which has some problems with multithreading.

Returns:
returns true if there is data available for reading; otherwise it returns false (if an error occurred or the operation timed out)

Definition at line 351 of file UdpDataProtocol.cpp.

References DataProtocol::mStopped, and signalWatingTooLong().

Referenced by run().

{
  int loop_resolution_usec = 100; // usecs to wait on each loop
  int emit_resolution_usec = 10000; // 10 milliseconds
  int timeout_usec = timeout_msec * 1000;
  int ellaped_time_usec = 0; // Ellapsed time in milliseconds

  while ( ( !(UdpSocket.hasPendingDatagrams()) && (ellaped_time_usec <= timeout_usec) )
    && !mStopped ){
    //cout << mStopped << endl;
    QThread::usleep(loop_resolution_usec);
    ellaped_time_usec += loop_resolution_usec;
    
    if ( !(ellaped_time_usec % emit_resolution_usec) ) {
      emit signalWatingTooLong(static_cast<int>(ellaped_time_usec/1000));
    }
  }
  
  if ( ellaped_time_usec >= timeout_usec )
  {
    emit signalWatingTooLong(ellaped_time_usec/1000);
    return false;
  }
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index