jessiemmichael
3rd September 2009, 07:51
I implement an UI application, that handles receiving data from tcp socket in a separate thread.
I use the following code to read data:
QByteArray data;
data = m_Connection->readAll();
m_CurrentResponse->insert(m_CurrentResponse->size(), data);
while (isResponseFull(m_CurrentResponse))
{
QByteArray* response = new QByteArray(m_CurrentResponse->data(), m_CurrentResponse->size());
unsigned int len = // read the 4 bytes to get the length of the responce
response->remove(len, (m_CurrentResponse->size() - len));
m_CurrentResponse->remove(0, len);
processResponse(response);
delete(response);
}
It crashes at readAll after few minutes. The server sends image data for every 1 ms. The client application should not block while processing data.
1) Is there any issue in calling readAll when bytesAvailable is more in number?
2) setReadBufferSize does not help in setting buffer size. Is there any way to restrict to limit receiving data internally in tcpSocket object
I use the following code to read data:
QByteArray data;
data = m_Connection->readAll();
m_CurrentResponse->insert(m_CurrentResponse->size(), data);
while (isResponseFull(m_CurrentResponse))
{
QByteArray* response = new QByteArray(m_CurrentResponse->data(), m_CurrentResponse->size());
unsigned int len = // read the 4 bytes to get the length of the responce
response->remove(len, (m_CurrentResponse->size() - len));
m_CurrentResponse->remove(0, len);
processResponse(response);
delete(response);
}
It crashes at readAll after few minutes. The server sends image data for every 1 ms. The client application should not block while processing data.
1) Is there any issue in calling readAll when bytesAvailable is more in number?
2) setReadBufferSize does not help in setting buffer size. Is there any way to restrict to limit receiving data internally in tcpSocket object