summaryrefslogtreecommitdiffstats
path: root/src/serialport/qserialport_win.cpp
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-06-28 00:11:29 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-07-07 14:00:58 +0000
commitb32740001f735be9f0938f85d325dc2cf3dbe598 (patch)
treece8114932e30c620642e68ca5fdfe6694fb2b356 /src/serialport/qserialport_win.cpp
parent77c48a0e22c1048226832e6b845d72da9d5b317f (diff)
Fix reading when switching from asynchronous to synchronous approach
If one wants to use the asynchronous approach (using the signals and slots), and then - the synchronous (using the waitForXX functions) then synchronous reading stalls because the waitForReadyRead() method always returns the TimeoutError code. The reason is that the signal readyRead() is emitted before the startAsyncRead() (or the startAsyncCommunication()) called inside of completeAsyncRead(). Need to emit the readyRead() only after the next asynchronous reading (the startAsyncRead() or the startAsyncCommunication()) was cocked. Now the behavior is similar to behavior of QWindowsPipeReader. Besides, the auto-test which reveals this issue is added. Tested with the virtual com0com serial ports, using the auto-tests and set of the examples. Change-Id: I64bfb871d17c179f474d6672546e532566913a7f Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com> Reviewed-by: Andrzej Ostruszka <andrzej.ostruszka@gmail.com>
Diffstat (limited to 'src/serialport/qserialport_win.cpp')
-rw-r--r--src/serialport/qserialport_win.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index b01d2d0e..57b70966 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -426,18 +426,20 @@ bool QSerialPortPrivate::completeAsyncRead(qint64 bytesTransferred)
if (bytesTransferred > 0) {
char *ptr = buffer.reserve(bytesTransferred);
::memcpy(ptr, readChunkBuffer.constData(), bytesTransferred);
- if (!emulateErrorPolicy())
- emitReadyRead();
}
readStarted = false;
+ bool result = true;
if ((bytesTransferred == ReadChunkSize) && (policy == QSerialPort::IgnorePolicy))
- return startAsyncRead();
+ result = startAsyncRead();
else if (readBufferMaxSize == 0 || readBufferMaxSize > buffer.size())
- return startAsyncCommunication();
- else
- return true;
+ result = startAsyncCommunication();
+
+ if ((bytesTransferred > 0) && !emulateErrorPolicy())
+ emitReadyRead();
+
+ return result;
}
bool QSerialPortPrivate::completeAsyncWrite(qint64 bytesTransferred)