[Interest] Odd behavior with QTcpSocket::waitForReadyRead()

Bob Hood bhood2 at comcast.net
Tue Dec 20 04:08:36 CET 2016


I'm refactoring the old code (modeled on Stevens' "UNIX Network Programming") 
to use the more modern Qt paradigm of signals/slots for async communications.  
So, the need for using waitforReadyRead() is obviated.

I'm guessing the timeout period being used greatly exceeds the underlying 
stack's more "reasonable" timeout values, but it still seems odd that it would 
not wait even fractions of a second for communications to complete.

Anyway, side-stepping the problem...

On 12/19/2016 4:38 PM, Bob Hood wrote:
> I'm porting a TCP/IP client from wxWdigets to Qt. I've tried this under both 
> 5.4.2 and 5.6.2.
>
> I have a user-configured timeout value for network reads.  The default is 
> 300 seconds (5 minutes).  I am feeding that to 
> QTcpSocket::waitForReadyRead(), and it's basically ignoring--worse, it's 
> generating an error.  It doesn't seem to matter if it's 300,000 msecs or 
> 3,000,000 msecs, I get "Network operation timed out" (5) returned from it.
>
>         int msecs = timeout * 1000000;
>         if(!socket.waitForReadyRead(msecs))
>         {
>             QString msg = QString(tr("An error occurred while receiving data 
> from the server: \"%1\" (%2).")).arg(socket.errorString()).arg(socket.error());
>             ...
>
> This causes the communications to fail, even though the action takes place 
> pretty much instantly, because I'm running the server on the same machine 
> for testing/debugging.  If I tell QTcpSocket::waitForReadyRead() to wait 
> forever:
>
>         if(!socket.waitForReadyRead(-1))
>
> everything runs smoothly.
>
> I've done nothing with the QTcpSocket instance in terms of configuration.  I 
> just create it, and then start the ball rolling with a call to 
> connectToHost().  Have I not configured some Qt5-thing correctly?




More information about the Interest mailing list