Hi all,
Does anyone know the size at which the buffer is filled when readyRead signal is emitted?
Thanks in advance.
Pedro Doria Meunier.
Hi all,
Does anyone know the size at which the buffer is filled when readyRead signal is emitted?
Thanks in advance.
Pedro Doria Meunier.
As soon as there is something in the buffer (even if it's a single byte). Look in bool QAbstractSocketPrivate::_q_canReadNotification() in src/network/qabstractsocket.cp
pdoria (1st February 2008)
Txs for your answer.
I've got a situation here where I cannot determine whether it's the device tx scheme or the size of the socket read buffer than come into play...
The thing is:
The device reports n Bytes to be read (the physical thing).
and the readyRead gets fired at 255 bytes.
So when I try to parse the data I'm n bytes short.
Dirty solution:
In the method connected to the readyRead signal I compare the tcpSocket.bytesAvailable() to the # of bytes the device says it wants to transmit.
In a nutshell:
Qt Code:
if (totalBytes < dataLength) { tcpSocket.waitForReadyRead(5000); }To copy to clipboard, switch view to plain text mode
Bottom line (and question):
Is there anyway to wait until n Bytes are available in the buffer instead of n milliseconds?
Thanks in advance.
Pedro Doria Meunier.
TCP is a stream based protocol... you will get data... but no fixed length.
to read N bytes... u can connect the readyRead to a slot, and have a static buffer there. When the bytes read equals N bytes, u can call some member function to process the N bytes.
Qt Code:
MySocket::OnReadyRead() { static buffer[1024]; buffer = readAll(); if(buffer.lenght() >= m_N) { processNbytes(buffer); buffer.clear(); } }To copy to clipboard, switch view to plain text mode
It's 1000000 times better to just leave the data in the socket, and return. The next time this signal is fired, you'll probably have enough. So:
Qt Code:
void MyClass::slotConnectedToReadyRead() { // Bad: data += readAll(); // unnecessary copy if (data.size() < 256) return; // Good: if (bytesAvailable() < 256) return; }To copy to clipboard, switch view to plain text mode
Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
Nokia Software Manager, Qt Development
Bookmarks