summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-06-07 23:22:19 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-12 16:21:09 +0200
commit450f79d2a1a38fd3d24df951758404cbcce158a8 (patch)
treeb17070301396402a4c5c470e6c81a6cb04836a64
parentedc0605ff92ada693323d995b27534d327224f6f (diff)
downloadqtserialport-450f79d2a1a38fd3d24df951758404cbcce158a8.tar.gz
Remove the exception notifier handling for *nix
The exception notifier does not do any useful operation while processing I/O but only complicates error handling. It has been thoughtlessly introduced at beginning in hope that in the future it can it is useful, but the practice showed that it not so. Problem is that in case of ejection of an open USB device from a host there is the infinite triggering of the exception notifier that leads to program hangup. We could stop an exception notifier in this case, but it not rationally because after the exception notifier is triggered the read notifier which also enters the infinite loop. Thus the read notifier anyway duplicates the exception notifier, as for functionality and as for an error code. Therefore more rationally to completely remove the exception notifier. So in case of the ResourceError we need just to stop of the read notifier, because it is a critical error. Then an user will be notified on the ResourceError appearance and must to close the device himself. Though work was checked only on Linux, but we can do not worry, and to refuse from this notifier in MacOSX also. Because anyway in MacOSX this type of notifier is not supported, at least from the Qt 5.1 and above: https://qt.gitorious.org/qt/qtbase/source/982fdd4ef556f63ba77384a0dbe97928e610091b:src/platformsupport/cfsocketnotifier/qcfsocketnotifier.cpp#L210 Besides in documentation on QSocketNotifier is recommended do not use the Exception mode: http://qt-project.org/doc/qt-5/qsocketnotifier.html#Type-enum Tested on ArchLinux 64 bit with the USB PL2303 device, ZTE modem, Android serial port using Qt4 and then Qt5. Task-number: QTBUG-36727 Task-number: QTBUG-35829 Change-Id: I4ea6db2a1c7f10c096d57817c00edefc4f0595ff Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com> Reviewed-by: Peter Kümmel <syntheticpp@gmx.net> Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
-rw-r--r--src/serialport/qserialport_unix.cpp57
-rw-r--r--src/serialport/qserialport_unix_p.h4
2 files changed, 2 insertions, 59 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index aa0d457..70c160b 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -147,27 +147,6 @@ private:
QSerialPortPrivate *dptr;
};
-class ExceptionNotifier : public QSocketNotifier
-{
- Q_OBJECT
-public:
- ExceptionNotifier(QSerialPortPrivate *d, QObject *parent)
- : QSocketNotifier(d->descriptor, QSocketNotifier::Exception, parent)
- , dptr(d)
- {}
-
-protected:
- bool event(QEvent *e) Q_DECL_OVERRIDE {
- bool ret = QSocketNotifier::event(e);
- if (ret)
- dptr->exceptionNotification();
- return ret;
- }
-
-private:
- QSerialPortPrivate *dptr;
-};
-
#include "qserialport_unix.moc"
QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
@@ -175,7 +154,6 @@ QSerialPortPrivate::QSerialPortPrivate(QSerialPort *q)
, descriptor(-1)
, readNotifier(0)
, writeNotifier(0)
- , exceptionNotifier(0)
, readPortNotifierCalled(false)
, readPortNotifierState(false)
, readPortNotifierStateSet(false)
@@ -256,8 +234,6 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
if (!updateTermios())
return false;
- setExceptionNotificationEnabled(true);
-
if ((flags & O_WRONLY) == 0)
setReadNotificationEnabled(true);
@@ -292,12 +268,6 @@ void QSerialPortPrivate::close()
writeNotifier = 0;
}
- if (exceptionNotifier) {
- exceptionNotifier->setEnabled(false);
- exceptionNotifier->deleteLater();
- exceptionNotifier = 0;
- }
-
if (qt_safe_close(descriptor) == -1)
q->setError(decodeSystemError());
@@ -816,6 +786,8 @@ bool QSerialPortPrivate::readNotification()
QSerialPort::SerialPortError error = decodeSystemError();
if (error != QSerialPort::ResourceError)
error = QSerialPort::ReadError;
+ else
+ setReadNotificationEnabled(false);
q->setError(error);
readBuffer.chop(bytesToRead);
return false;
@@ -900,14 +872,6 @@ bool QSerialPortPrivate::completeAsyncWrite()
return startAsyncWrite();
}
-void QSerialPortPrivate::exceptionNotification()
-{
- Q_Q(QSerialPort);
-
- QSerialPort::SerialPortError error = decodeSystemError();
- q->setError(error);
-}
-
bool QSerialPortPrivate::updateTermios()
{
Q_Q(QSerialPort);
@@ -992,23 +956,6 @@ void QSerialPortPrivate::setWriteNotificationEnabled(bool enable)
}
}
-bool QSerialPortPrivate::isExceptionNotificationEnabled() const
-{
- return exceptionNotifier && exceptionNotifier->isEnabled();
-}
-
-void QSerialPortPrivate::setExceptionNotificationEnabled(bool enable)
-{
- Q_Q(QSerialPort);
-
- if (exceptionNotifier) {
- exceptionNotifier->setEnabled(enable);
- } else if (enable) {
- exceptionNotifier = new ExceptionNotifier(this, q);
- exceptionNotifier->setEnabled(true);
- }
-}
-
bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectForWrite,
bool checkRead, bool checkWrite,
int msecs, bool *timedOut)
diff --git a/src/serialport/qserialport_unix_p.h b/src/serialport/qserialport_unix_p.h
index 5804a2b..64d1d9e 100644
--- a/src/serialport/qserialport_unix_p.h
+++ b/src/serialport/qserialport_unix_p.h
@@ -124,7 +124,6 @@ public:
bool readNotification();
bool startAsyncWrite();
bool completeAsyncWrite();
- void exceptionNotification();
static QString portNameToSystemLocation(const QString &port);
static QString portNameFromSystemLocation(const QString &location);
@@ -140,7 +139,6 @@ public:
QSocketNotifier *readNotifier;
QSocketNotifier *writeNotifier;
- QSocketNotifier *exceptionNotifier;
bool readPortNotifierCalled;
bool readPortNotifierState;
@@ -169,8 +167,6 @@ private:
void setReadNotificationEnabled(bool enable);
bool isWriteNotificationEnabled() const;
void setWriteNotificationEnabled(bool enable);
- bool isExceptionNotificationEnabled() const;
- void setExceptionNotificationEnabled(bool enable);
bool waitForReadOrWrite(bool *selectForRead, bool *selectForWrite,
bool checkRead, bool checkWrite,