From ed0c0070f9b05c647019270dfc42073d071c830a Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Mon, 8 Dec 2014 15:29:19 +0100 Subject: 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 --- src/network/ssl/qsslsocket.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src/network/ssl') 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()); -- cgit v1.2.3