summaryrefslogtreecommitdiffstats
path: root/src/serialport/qserialport_unix_p.h
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2014-01-22 17:52:16 +0400
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-12 18:15:43 +0100
commit21f50498f7558e59bca8789e94c0fe5d14a9e27d (patch)
tree837358206dac60ddd67814f0ecfe4e602bf8f819 /src/serialport/qserialport_unix_p.h
parent18de39f7620ba4111f3846d4e8ea67aa5b701940 (diff)
Do not emit bytesWritten() while data aren't transferred
The serial port very slow device therefore the system call write() doesn't guarantee that data were transferred completely to the device. It guarantee only that data were sent to the driver from the user space. Thus it is wrong to emit the bytesWritten() signal at once after successful writing. The correct solution is to store the number of transferred data in some variable (e.g. pendingBytesWritten in this case) and to wait for the next notification from the WriteNotifier that the write FIFO of device is empty (i.e. when all data were really transferred) and ready to transmission of the next portion of data. Also good decision is to divide a data transfer operation into two methods: startAsyncWrite() and completeAsyncWrite(), similar with the Windows implementation. Where the startAsyncWrite() invokes the write() system call, and the completeAsyncWrite() is invoked by a writeNotifier to complete writing operation or start a new startAsyncWrite() operation. Tested on Arch Linux 64 bit with the on-board and the USB (PL2303) serial ports with use Qt4 and then Qt5. Change-Id: I1c274b2052a9bd54811586c6f1cfdf080b400263 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport/qserialport_unix_p.h')
-rw-r--r--src/serialport/qserialport_unix_p.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/serialport/qserialport_unix_p.h b/src/serialport/qserialport_unix_p.h
index 1960316a..ed86fc89 100644
--- a/src/serialport/qserialport_unix_p.h
+++ b/src/serialport/qserialport_unix_p.h
@@ -121,7 +121,8 @@ public:
bool setDataErrorPolicy(QSerialPort::DataErrorPolicy policy);
bool readNotification();
- bool writeNotification();
+ bool startAsyncWrite();
+ bool completeAsyncWrite();
void exceptionNotification();
static QString portNameToSystemLocation(const QString &port);
@@ -152,6 +153,9 @@ public:
bool emittedReadyRead;
bool emittedBytesWritten;
+ qint64 pendingBytesWritten;
+ bool writeSequenceStarted;
+
QScopedPointer<QLockFile> lockFileScopedPointer;
private: