diff options
author | Daniel Teske <daniel.teske@theqtcompany.com> | 2014-12-08 15:29:19 +0100 |
---|---|---|
committer | Daniel Teske <daniel.teske@theqtcompany.com> | 2015-03-09 17:11:54 +0000 |
commit | ed0c0070f9b05c647019270dfc42073d071c830a (patch) | |
tree | 59a4996d3de61489254b3cb8a85b6d2c83a19bd3 /src/corelib/io/qiodevice.cpp | |
parent | 5bf9528b9164bd888e991552b66d6237e84a7ee2 (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/corelib/io/qiodevice.cpp')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index f1c42c9bb5..35911934df 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1667,6 +1667,23 @@ QString QIODevice::errorString() const \sa read(), write() */ +/*! + \internal + \fn int qt_subtract_from_timeout(int timeout, int elapsed) + + Reduces the \a timeout by \a elapsed, taking into account that -1 is a + special value for timeouts. +*/ + +int qt_subtract_from_timeout(int timeout, int elapsed) +{ + if (timeout == -1) + return -1; + + timeout = timeout - elapsed; + return timeout < 0 ? 0 : timeout; +} + #if !defined(QT_NO_DEBUG_STREAM) QDebug operator<<(QDebug debug, QIODevice::OpenMode modes) |