From 4ff8b20cf2877298c8437fb892ebda600f46e293 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 18 Dec 2015 22:53:14 +0300 Subject: Suppress error emission when closing When the error signal is connected to a slot which calls QSP::close() and an error occurs in this method, this would lead to infinite recursion. Other Qt I/O classes avoid this problem by not emitting errors while closing the device, so we should not, either. Task-number: QTBUG-50052 Change-Id: Icfbcb19c32b8bd7fc586ab5253dc754e78829f11 Reviewed-by: Sergey Belyashov Reviewed-by: Denis Shienkov --- src/serialport/qserialport_unix.cpp | 12 ++++-------- src/serialport/qserialport_win.cpp | 13 ++++--------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index 960349e..7153449 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -237,14 +237,11 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) void QSerialPortPrivate::close() { - if (settingsRestoredOnClose) { - if (::tcsetattr(descriptor, TCSANOW, &restoredTermios) == -1) - setError(getSystemError()); - } + if (settingsRestoredOnClose) + ::tcsetattr(descriptor, TCSANOW, &restoredTermios); #ifdef TIOCNXCL - if (::ioctl(descriptor, TIOCNXCL) == -1) - setError(getSystemError()); + ::ioctl(descriptor, TIOCNXCL); #endif if (readNotifier) { @@ -257,8 +254,7 @@ void QSerialPortPrivate::close() writeNotifier = Q_NULLPTR; } - if (qt_safe_close(descriptor) == -1) - setError(getSystemError()); + qt_safe_close(descriptor); lockFileScopedPointer.reset(Q_NULLPTR); diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 6e1a44f..f176025 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -104,8 +104,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode) void QSerialPortPrivate::close() { - if (!::CancelIo(handle)) - setError(getSystemError()); + ::CancelIo(handle); if (notifier) { delete notifier; @@ -124,15 +123,11 @@ void QSerialPortPrivate::close() actualBytesToWrite = 0; if (settingsRestoredOnClose) { - if (!::SetCommState(handle, &restoredDcb)) - setError(getSystemError()); - else if (!::SetCommTimeouts(handle, &restoredCommTimeouts)) - setError(getSystemError()); + ::SetCommState(handle, &restoredDcb); + ::SetCommTimeouts(handle, &restoredCommTimeouts); } - if (!::CloseHandle(handle)) - setError(getSystemError()); - + ::CloseHandle(handle); handle = INVALID_HANDLE_VALUE; } -- cgit v1.2.1