qt-bugs@ issue : N188142 Trolltech task ID : 188329 (status: fixed for Qt 4.4.0) bugs.kde.org number : None applied: no author: Andreas Hartmetz <ahartmetz@gmail.com> This patch fixes that some QSslSocket::waitFor$X methods, when passed -1 as the argument, behave as if they were passed 0. -1 is supposed to mean "wait indefi- nitely" while 0 means "don't wait". Index: src/network/qsslsocket.cpp =================================================================== --- src/network/qsslsocket.cpp (Revision 738032) +++ src/network/qsslsocket.cpp (Arbeitskopie) @@ -251,6 +251,19 @@ #include <QtNetwork/qhostaddress.h> #include <QtNetwork/qhostinfo.h> +/* + Returns the difference between msecs and elapsed. If msecs is -1, + however, -1 is returned. +*/ +static int qt_timeout_value(int msecs, int elapsed) +{ + if (msecs == -1) + return -1; + + int timeout = msecs - elapsed; + return timeout < 0 ? 0 : timeout; +} + class QSslSocketGlobalData { public: @@ -1110,7 +1123,7 @@ startClientEncryption(); // Loop, waiting until the connection has been encrypted or an error // occurs. - if (!d->plainSocket->waitForReadyRead(qBound(0, msecs - stopWatch.elapsed(), msecs))) + if (!d->plainSocket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) return false; } return d->connectionEncrypted; @@ -1138,7 +1151,7 @@ return false; } - while (d->plainSocket->waitForReadyRead(qBound(0, msecs - stopWatch.elapsed(), msecs))) { + while (d->plainSocket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) { if (d->readBuffer.size() != oldReadBufferSize) { // If the read buffer has grown, readyRead() must have been emitted. return true; @@ -1167,7 +1180,7 @@ return false; } - return d->plainSocket->waitForBytesWritten(qBound(0, msecs - stopWatch.elapsed(), msecs)); + return d->plainSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed())); } /*!