summaryrefslogtreecommitdiffstats
path: root/src/network/ssl
diff options
context:
space:
mode:
authorDaniel Teske <daniel.teske@theqtcompany.com>2014-12-08 15:29:19 +0100
committerDaniel Teske <daniel.teske@theqtcompany.com>2015-03-09 17:11:54 +0000
commited0c0070f9b05c647019270dfc42073d071c830a (patch)
tree59a4996d3de61489254b3cb8a85b6d2c83a19bd3 /src/network/ssl
parent5bf9528b9164bd888e991552b66d6237e84a7ee2 (diff)
Introduce qt_subtract_from_timeout to reduce code duplication.
The same qt_timeout_value function was copied 5 times in qtbase's code, so provide a common implementation in QIoDevice that can be used by everyone. This commit also corrects the remaining time calculation in QProcess::waitForBytesWritten and QProcess::waitForFinished by using this new function. For QProcess::waitForFinished, if the process started within almost exactly the timeout time passed to waitForFinished, msecs - stopWatch.elapsed() would be -1, which is a special value. Change-Id: I7b76ee6bae695eafdd02e3db03e2ff1e23a7f40c Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/network/ssl')
-rw-r--r--src/network/ssl/qsslsocket.cpp21
1 files changed, 4 insertions, 17 deletions
diff --git a/src/network/ssl/qsslsocket.cpp b/src/network/ssl/qsslsocket.cpp
index c0c15fb5b1..39cd562bc4 100644
--- a/src/network/ssl/qsslsocket.cpp
+++ b/src/network/ssl/qsslsocket.cpp
@@ -301,19 +301,6 @@
QT_BEGIN_NAMESPACE
-/*
- 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:
@@ -1518,7 +1505,7 @@ bool QSslSocket::waitForEncrypted(int msecs)
startClientEncryption();
// Loop, waiting until the connection has been encrypted or an error
// occurs.
- if (!d->plainSocket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed())))
+ if (!d->plainSocket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed())))
return false;
}
return d->connectionEncrypted;
@@ -1562,7 +1549,7 @@ bool QSslSocket::waitForReadyRead(int msecs)
// test readyReadEmitted first because either operation above
// (waitForEncrypted or transmit) may have set it
while (!readyReadEmitted &&
- d->plainSocket->waitForReadyRead(qt_timeout_value(msecs, stopWatch.elapsed()))) {
+ d->plainSocket->waitForReadyRead(qt_subtract_from_timeout(msecs, stopWatch.elapsed()))) {
}
d->readyReadEmittedPointer = previousReadyReadEmittedPointer;
@@ -1593,7 +1580,7 @@ bool QSslSocket::waitForBytesWritten(int msecs)
d->transmit();
}
- return d->plainSocket->waitForBytesWritten(qt_timeout_value(msecs, stopWatch.elapsed()));
+ return d->plainSocket->waitForBytesWritten(qt_subtract_from_timeout(msecs, stopWatch.elapsed()));
}
/*!
@@ -1626,7 +1613,7 @@ bool QSslSocket::waitForDisconnected(int msecs)
if (!waitForEncrypted(msecs))
return false;
}
- bool retVal = d->plainSocket->waitForDisconnected(qt_timeout_value(msecs, stopWatch.elapsed()));
+ bool retVal = d->plainSocket->waitForDisconnected(qt_subtract_from_timeout(msecs, stopWatch.elapsed()));
if (!retVal) {
setSocketState(d->plainSocket->state());
setSocketError(d->plainSocket->error());