diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2014-11-21 22:20:41 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2014-11-27 12:31:24 +0100 |
commit | 38f43b390e5b27f6243ba781394ad2418ead6b74 (patch) | |
tree | 73e7c24489ba463e430206b35e5fc855e7f7ef34 /src/serialport/qserialport_p.h | |
parent | 721faa9486dc0a6d8b6e1f2214ae040a2264a2e3 (diff) | |
download | qtserialport-38f43b390e5b27f6243ba781394ad2418ead6b74.tar.gz |
Use QWinOverlappedIoNotifier instead of QWinEventNotifier
The reasons of this change are following:
1) Implementation of QEventDispatcherWin32 has restrictions to
maximum quantity of QWinEvenNotifier instances in one thread.
Method QEventDispatcherWin32::registerEventNotifier() registers
the [MAXIMUM_WAIT_OBJECTS - 2] numbers of notifiers only. Where
the MAXIMUM_WAIT_OBJECTS that is equal to 64, since it is a part
of "Multiple-object Wait Functions" API:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms687069%28v=vs.85%29.aspx
2) There is need to have three instances of QWinEventNotifier to
watch I/O events of each serial port.
It has limits to the maximum number of used serial ports and it
is [(MAXIMUM_WAIT_OBJECTS - 2) / 3] = 20 for the one thread.
3) Attempting to move or to resize a window of GUI application
lead to suspending of I/O events from serial port.
A long suspension can lead to overflowing of FIFO of device, so
the data can be lost.
All these shortcomings are resolved with QWinOverlappedIoNotifier,
which uses the "I/O Completion Ports" API:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365198%28v=vs.85%29.aspx
Tested on Windows 8 with the virtual (com0com), on-board and
the USB (PL2303) serial ports.
Task-number: QTBUG-34946
Change-Id: I879d939f86c8dcde0fe21a8d6267e81152822aa4
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Diffstat (limited to 'src/serialport/qserialport_p.h')
-rw-r--r-- | src/serialport/qserialport_p.h | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h index 43a4f20..a62c3c5 100644 --- a/src/serialport/qserialport_p.h +++ b/src/serialport/qserialport_p.h @@ -101,7 +101,7 @@ QT_BEGIN_NAMESPACE #endif class QThread; -class QWinEventNotifier; +class QWinOverlappedIoNotifier; class QTimer; class QSocketNotifier; @@ -148,7 +148,7 @@ public: bool setFlowControl(QSerialPort::FlowControl flowControl); bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy); - QSerialPort::SerialPortError decodeSystemError() const; + QSerialPort::SerialPortError decodeSystemError(int systemErrorCode = -1) const; qint64 bytesToWrite() const; qint64 writeData(const char *data, qint64 maxSize); @@ -205,25 +205,22 @@ public: bool initialize(); bool updateDcb(); bool updateCommTimeouts(); - qint64 handleOverlappedResult(int direction, OVERLAPPED &overlapped); + qint64 overlappedResult(OVERLAPPED *overlapped); void handleLineStatusErrors(); - bool waitAnyEvent(int msecs, bool *timedOut, HANDLE *triggeredEvent); + OVERLAPPED *waitForNotified(int msecs); - bool _q_completeAsyncCommunication(); - bool _q_completeAsyncRead(); - bool _q_completeAsyncWrite(); + bool completeAsyncCommunication(qint64 bytesTransferred); + bool completeAsyncRead(qint64 bytesTransferred); + bool completeAsyncWrite(qint64 bytesTransferred); bool startAsyncCommunication(); bool startAsyncRead(); bool _q_startAsyncWrite(); + void _q_notified(DWORD numberOfBytes, DWORD errorCode, OVERLAPPED *overlapped); bool emulateErrorPolicy(); void emitReadyRead(); - bool setCommunicationNotificationEnabled(bool enable); - bool setReadNotificationEnabled(bool enable); - bool setWriteNotificationEnabled(bool enable); - DCB currentDcb; DCB restoredDcb; COMMTIMEOUTS currentCommTimeouts; @@ -234,9 +231,7 @@ public: bool readyReadEmitted; bool writeStarted; bool readStarted; - QWinEventNotifier *communicationNotifier; - QWinEventNotifier *readCompletionNotifier; - QWinEventNotifier *writeCompletionNotifier; + QWinOverlappedIoNotifier *notifier; QTimer *startAsyncWriteTimer; OVERLAPPED communicationOverlapped; OVERLAPPED readCompletionOverlapped; |