[Qt-interest] QTcpSocket::waitForReadyRead() "loses" data in a QThread with an event loop
FD
dof at projektfabrik.com
Sun Sep 5 21:49:27 CEST 2010
Hi Arnold,
thanks for your reply.
> waitForReadyRead() waits from the moment you call it for more data. if more
> data arrived between your last read and calling waitFor..., it doesn't
> return immediately.
Yes, I call waitForReadyRead() after I sent the command to the server. After
that, I am only calling read, because waitForReadyRead() wouldn't return. The
thing is, that the calls to read() after my initial call to
waitForReadyRead(), won't return any more data - I can try for ever, I'm not
able to get the rest of the data (read() returns 0)...
My initial solution was to parse a line of incoming data, and then read() more
data from the socket. That didn't work, so I changed my code to parse all
complete lines of data received up to this point from the server, and only
then, if data is missing, read() more. This (strangely enough) resulted in
that I was able to read more data from the socket than before - until the
server response got bigger (it is an IMAP session, so I do know when a command
is finished - whether it be ok or not)...
> If your network-messages are delimited by a specific character or string,
> try to peek into the received buffer and parse the answer if it contains
> the delimiter and idle for another round if it doesn't (yet) contain that
> delimiter.
As said on top, peeking doesn't work, as read()ing data won't return any.
Because of the nature of the IMAP protocol, I know when to expect more data.
Greetings...
More information about the Qt-interest-old
mailing list