From 728f3e7383ac6f7364126bf55684d51dec51cd69 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sun, 8 Sep 2013 22:43:57 +0400 Subject: Do not time out for -1 msec (wait methods) According to the documentation of QIODevice: * http://qt-project.org/doc/qt-5.1/qtcore/qiodevice.html#waitForBytesWritten * http://qt-project.org/doc/qt-5.1/qtcore/qiodevice.html#waitForReadyRead these wait methods should not time out if msecs is -1. Currently, the behavior does not match the expected behavior as the negative values were overridden by zero. The operation returns as soon as the event loop processing happens. Now this problem is solved for Windows: the INFINITE flag has been added to the WaitForMultipleObjects call. See the MSDN documentation for details below: http://msdn.microsoft.com/en-us/library/windows/desktop/ms687025%28v=vs.85%29.aspx Note: the check is added only for -1 to be consistent with the behavior of other QIODevice subclasses. If it is any other negative integer, the value will be cast to the corresponding positive value which will indicate the waiting time. Tested with Qt4 and then Qt5. Change-Id: I2b8c8310723bca7beb9af0213edf4c855b5ac6ae Reviewed-by: Laszlo Papp Reviewed-by: Sergey Belyashov --- src/serialport/qserialport_win.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index c515e82..1ab18a9 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -985,7 +985,7 @@ bool QSerialPortPrivate::waitAnyEvent(int msecs, bool *timedOut, DWORD waitResult = ::WaitForMultipleObjects(handles.count(), handles.constData(), FALSE, // wait any event - qMax(msecs, 0)); + msecs == -1 ? INFINITE : msecs); if (waitResult == WAIT_TIMEOUT) { *timedOut = true; return false; -- cgit v1.2.1