diff options
author | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2015-12-21 11:37:49 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@theqtcompany.com> | 2015-12-21 22:26:40 +0000 |
commit | e96fa5a780665e24fe4710868e399b3216a5d3b3 (patch) | |
tree | 4c84998f0a5e1c1407dbe212b1eb1f2b03941840 /tests/auto/other | |
parent | 1823c8f2ddd0a5c1b4301e7af7109796090a3c9a (diff) |
Fix timeout calculations using qt_subtract_from_timeout
Commit ed0c0070 introduced qt_subtract_from_timeout but used it
incorrectly in several places.
Change-Id: I80ea16088707929a45d5a61ec6f3370f8e63d1cd
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'tests/auto/other')
-rw-r--r-- | tests/auto/other/networkselftest/tst_networkselftest.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index 5612260cca..ca321fb6fd 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -169,14 +169,16 @@ static bool doSocketRead(QTcpSocket *socket, int minBytesAvailable, int timeout { QElapsedTimer timer; timer.start(); + int t = timeout; forever { if (socket->bytesAvailable() >= minBytesAvailable) return true; - timeout = qt_subtract_from_timeout(timeout, timer.elapsed()); - if (socket->state() == QAbstractSocket::UnconnectedState - || timeout == 0) + if (socket->state() == QAbstractSocket::UnconnectedState) return false; - if (!socket->waitForReadyRead(timeout)) + if (!socket->waitForReadyRead(t)) + return false; + t = qt_subtract_from_timeout(timeout, timer.elapsed()); + if (t == 0) return false; } } @@ -197,6 +199,7 @@ static bool doSocketFlush(QTcpSocket *socket, int timeout = 4000) #endif QTime timer; timer.start(); + int t = timeout; forever { if (socket->bytesToWrite() == 0 #ifndef QT_NO_SSL @@ -204,11 +207,12 @@ static bool doSocketFlush(QTcpSocket *socket, int timeout = 4000) #endif ) return true; - timeout = qt_subtract_from_timeout(timeout, timer.elapsed()); - if (socket->state() == QAbstractSocket::UnconnectedState - || timeout == 0) + if (socket->state() == QAbstractSocket::UnconnectedState) + return false; + if (!socket->waitForBytesWritten(t)) return false; - if (!socket->waitForBytesWritten(timeout)) + t = qt_subtract_from_timeout(timeout, timer.elapsed()); + if (t == 0) return false; } } |