diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2013-12-25 16:32:28 +0400 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-17 09:37:56 +0100 |
commit | 90dbacd9dae2b82fad9c68ca95c06a6d6b1ae030 (patch) | |
tree | 7a5ff731908abef99d187536896a18f720d3e6bd /src/serialport | |
parent | d5658bd0ced4a1eb0703d3cb1b566025d610fbdd (diff) | |
download | qtserialport-90dbacd9dae2b82fad9c68ca95c06a6d6b1ae030.tar.gz |
Fix the waitForReadyRead() behavior on Windows
It is necessary to compare size of the readBuffer before and after
completion of each read operation. If size of readBuffer are equal
it means that are no more data available for reading. In this case
the method should returns true if an initial size of readBuffer is
not equal to the current size of readBuffer. Otherwise in all other
cases should be continue waiting until timeout has been expired.
Also must not to do check for the NoError code and to hope for valid
value of this code inside waitForReadyRead(). Because a last error
code do not clears automatically. It lead to false returns of this
method in case the error number is not equal to NoError (for example
it error remained after failed of any previous method). This check
should be implemented in a different way in case of need. But at
present this check is unnecessary because result of the waitAnyEvent()
cover it.
Task-number: QTBUG-33987
Change-Id: Ic8d8e3806fd4863c2720ffb83d5c19eae54d57f0
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Laszlo Papp <lpapp@kde.org>
Diffstat (limited to 'src/serialport')
-rw-r--r-- | src/serialport/qserialport_win.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index e460c78..4a72da0 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -381,6 +381,9 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs) QElapsedTimer stopWatch; stopWatch.start(); + const qint64 initialReadBufferSize = readBuffer.size(); + qint64 currentReadBufferSize = initialReadBufferSize; + do { bool timedOut = false; HANDLE triggeredEvent = 0; @@ -394,11 +397,12 @@ bool QSerialPortPrivate::waitForReadyRead(int msecs) if (triggeredEvent == communicationOverlapped.hEvent) { _q_canCompleteCommunication(); - if (error != QSerialPort::NoError) - return false; } else if (triggeredEvent == readCompletionOverlapped.hEvent) { _q_canCompleteRead(); - return error == QSerialPort::NoError; + if (qint64(readBuffer.size()) != currentReadBufferSize) + currentReadBufferSize = readBuffer.size(); + else if (initialReadBufferSize != currentReadBufferSize) + return true; } else if (triggeredEvent == writeCompletionOverlapped.hEvent) { _q_canCompleteWrite(); } else { |