diff options
Diffstat (limited to 'src/serialport/qserialport_win.cpp')
-rw-r--r-- | src/serialport/qserialport_win.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp index 762deba..412e20c 100644 --- a/src/serialport/qserialport_win.cpp +++ b/src/serialport/qserialport_win.cpp @@ -112,15 +112,11 @@ void QSerialPortPrivate::close() { ::CancelIo(handle); - if (notifier) { - delete notifier; - notifier = Q_NULLPTR; - } + delete notifier; + notifier = Q_NULLPTR; - if (startAsyncWriteTimer) { - delete startAsyncWriteTimer; - startAsyncWriteTimer = Q_NULLPTR; - } + delete startAsyncWriteTimer; + startAsyncWriteTimer = Q_NULLPTR; communicationStarted = false; readStarted = false; @@ -443,10 +439,13 @@ bool QSerialPortPrivate::completeAsyncRead(qint64 bytesTransferred) readStarted = false; bool result = true; - if (bytesTransferred == ReadChunkSize) + if (bytesTransferred == ReadChunkSize + || queuedBytesCount(QSerialPort::Input) > 0) { result = startAsyncRead(); - else if (readBufferMaxSize == 0 || readBufferMaxSize > buffer.size()) + } else if (readBufferMaxSize == 0 + || readBufferMaxSize > buffer.size()) { result = startAsyncCommunication(); + } if (bytesTransferred > 0) emitReadyRead(); @@ -604,6 +603,16 @@ OVERLAPPED *QSerialPortPrivate::waitForNotified(int msecs) return overlapped; } +qint64 QSerialPortPrivate::queuedBytesCount(QSerialPort::Direction direction) const +{ + COMSTAT comstat; + if (::ClearCommError(handle, Q_NULLPTR, &comstat) == 0) + return -1; + return (direction == QSerialPort::Input) + ? comstat.cbInQue + : ((direction == QSerialPort::Output) ? comstat.cbOutQue : -1); +} + inline bool QSerialPortPrivate::initialize() { Q_Q(QSerialPort); |