Hi all,

I Use QTcpSocket to sendrequest to a device and in turn that device will answer, and I should not send another request until that device has all its reply sent.

Request are small messages like max of 20 bytes but reply can vary from 10 000 to 30 000 bytes.

Reply is stuctured by blocks and a reply may contain several blocks


so I connected QTcpSocket::readyRead() signal to my readData slot (see below for readData slot implementation

Qt Code:
  1. void Myclass::readData ()
  2. {
  3. QByteArray incomingBlock;
  4. while (m_deviceLink->socketMscope->bytesAvailable()) // I am suppose to suck all the reply with this
  5. {
  6. QByteArray packet = m_tcpSocket-> readAll();
  7. // append new data to block buffer
  8. incomingBlock.append(packet);
  9.  
  10. // check if its atleast a header
  11. if ( incomingBlock.count() > (int) sizeof(t_blockHeader))
  12. {
  13. m_response = *(t_blockHeader*)incomingBlock.constData();
  14. if (!isChecksumValid((uint8*)&m_response,sizeof(t_blockHeader))) // a header has checksum to verify its validity
  15. {
  16. emit errorCheckSum();
  17. incomingBlock.clear();
  18. break;
  19. }
  20. if (incomingBlock.count() == (int)(sizeof(t_blockHeader+m_response.dataLength))
  21. {
  22. // i got one block (header + data ) so I am suppose to proccess this then throw away the copy of the received socket data.
  23. m_incomingBlock.clear();
  24. }
  25. else if (m_incomingBlock.count() > (int)(sizeof(t_blockHeader)+ m_response.frameLength))
  26. {
  27. //I am expecting some more burst of data from the socket since some blocks are unfinished but processed the first complete block and trimmed incoming buffer
  28. m_incomingBlock = m_incomingBlock.mid(sizeof(t_blockHeader)+ m_response.dataLength);
  29. }
  30. else
  31. {
  32. // do nothing since received bytes is not even equal to one block
  33. }
  34. }
  35.  
  36. }
  37. emit readyForData(); //this will signal my requester class to send another request
To copy to clipboard, switch view to plain text mode 

So, I expected to have all my reply after the while loop but I was wrong my while exited halfway of the transmission of the reply

Now, My Question is how can i suck all the large messages before exiting my while loop?

I guess my payLoad of data is governed by tcpSocket buffer size, So I won't expect reply from the other side to be in one single shot of payLoad.