summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-06-07 14:04:12 +0400
committerDenis Shienkov <denis.shienkov@gmail.com>2014-06-29 18:06:37 +0200
commit38f564f7255330710defcf839f4cd04e1ccfc417 (patch)
treed0be41196bdb2a6878a6af1567d12183b11038b2
parent406d8d83cc11601d7121f1cb5de806a090080ddd (diff)
downloadqtserialport-38f564f7255330710defcf839f4cd04e1ccfc417.tar.gz
Improve the I/O completion errors handling on Windows
* It is necessary to ignore the NoError error code. * In case of error from GetOverlappedResult() it is necessary to stop the I/O operation by a immediate return from the function, because I/O processing does not make sense. This is consistent behavior similar to starting I/O operations. * All errors from the read completion should be interpreted as ReadError. Exception is only the critical ResourceError error which it is necessary to leave without changes. This is also consistent behavior similar to starting I/O operations. * The write completion error handling should be similar to the read completion handling. * For the communication completion we have no specific error codes. Therefore error handling shall be without modification of their error code. Also were made small cosmetic fixes to the related start I/O methods. Tested on Windows 7/8 with the on-board, the PL2303 and the virtual com0com serial ports using Qt4 and then Qt5. Testing are made by means of examples of library and also by means of auto tests, no regressions found. Change-Id: I0d08b53627431c42ab5147d4330f1aaf819b4d63 Reviewed-by: Peter Kümmel <syntheticpp@gmx.net> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
-rw-r--r--src/serialport/qserialport_win.cpp32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index 111a8ce..981ec2e 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -567,8 +567,13 @@ void QSerialPortPrivate::_q_completeAsyncCommunication()
DWORD numberOfBytesTransferred = 0;
- if (!::GetOverlappedResult(handle, &communicationOverlapped, &numberOfBytesTransferred, FALSE))
- q->setError(decodeSystemError());
+ if (!::GetOverlappedResult(handle, &communicationOverlapped, &numberOfBytesTransferred, FALSE)) {
+ const QSerialPort::SerialPortError error = decodeSystemError();
+ if (error != QSerialPort::NoError) {
+ q->setError(error);
+ return;
+ }
+ }
bool error = false;
@@ -600,8 +605,15 @@ void QSerialPortPrivate::_q_completeAsyncRead()
Q_Q(QSerialPort);
DWORD numberOfBytesTransferred = 0;
- if (!::GetOverlappedResult(handle, &readCompletionOverlapped, &numberOfBytesTransferred, FALSE))
- q->setError(decodeSystemError());
+ if (!::GetOverlappedResult(handle, &readCompletionOverlapped, &numberOfBytesTransferred, FALSE)) {
+ QSerialPort::SerialPortError error = decodeSystemError();
+ if (error != QSerialPort::NoError) {
+ if (error != QSerialPort::ResourceError)
+ error = QSerialPort::ReadError;
+ q->setError(error);
+ return;
+ }
+ }
if (numberOfBytesTransferred > 0) {
@@ -627,8 +639,13 @@ void QSerialPortPrivate::_q_completeAsyncWrite()
DWORD numberOfBytesTransferred = 0;
if (!::GetOverlappedResult(handle, &writeCompletionOverlapped, &numberOfBytesTransferred, FALSE)) {
numberOfBytesTransferred = 0;
- q->setError(decodeSystemError());
- return;
+ QSerialPort::SerialPortError error = decodeSystemError();
+ if (error != QSerialPort::NoError) {
+ if (error != QSerialPort::ResourceError)
+ error = QSerialPort::WriteError;
+ q->setError(error);
+ return;
+ }
}
if (numberOfBytesTransferred > 0) {
@@ -648,7 +665,7 @@ bool QSerialPortPrivate::startAsyncCommunication()
if (!::WaitCommEvent(handle, &triggeredEventMask, &communicationOverlapped)) {
const QSerialPort::SerialPortError error = decodeSystemError();
if (error != QSerialPort::NoError) {
- q->setError(decodeSystemError());
+ q->setError(error);
return false;
}
}
@@ -679,7 +696,6 @@ bool QSerialPortPrivate::startAsyncRead()
if (error != QSerialPort::ResourceError)
error = QSerialPort::ReadError;
q->setError(error);
-
return false;
}