Hi,

I want to reimplement the QIODevice's read

Qt Code:
  1. qint64 QIODevice::read ( char * data, qint64 maxSize )
To copy to clipboard, switch view to plain text mode 

as follows:

- I want the new Read function to block until it has filled nBytes that I want to read.

Would this function do?

Qt Code:
  1. bool Read( char* address,
  2. int numBytesToBeRead )
  3. {
  4. do
  5. {
  6. // If waitForReadyRead returns false, there is something wrong
  7. if( mDevice->waitForReadyRead( -1 ) == false )
  8. {
  9. return false;
  10. }
  11. } while( mDevice->bytesAvailable() != numBytesToRead );
  12.  
  13. // Now that there are numBytesToBeRead available, read it all at once
  14. mDevice->read( address, numBytesToBeRead );
  15.  
  16. return true;
  17. }
To copy to clipboard, switch view to plain text mode 

A few concerns:

1) Once there is at least 1 byte to be read in the "pipe," would waitForReadyRead() constantly return? i.e. it wont block anymore since there are bytes to be read even if it's not up to the number of bytes I want to read yet.

2) Can it be that the "pipe" would eventually be full and that bytesAvailable() will never be equal to numBytesToRead? i.e. if numBytesToRead is 1 GB...maybe if the program doesnt do a read() at all, bytesAvailable will never be equal to 1GB.

I simply just want an API that's like the POSIX TCP socket where the read() blocks forever waiting for X amount of bytes to come through. Is there something similar in Qt?