diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2013-02-28 23:30:37 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-02 18:47:29 +0100 |
commit | 0d5d7cb9b5bcebec79b2de6acb43da1b05ad82f6 (patch) | |
tree | db40feab2c7185e7cc0f06714a75d0898a7673b4 | |
parent | feae6e4634e18516e4f64a20d55f98f40a20cd9e (diff) |
*nix: Fix unexpected clear errno when I/O failed
This bug was detected on MacOSX 10.8 & FTDI serial device.
When removing a previously opened device from the system, triggered
readNotifier() and are trying to read() from the device, but call
returns -1 with errno = 6. It is correct behavior.
But then, when called decodeSystemError(), the now value of errno
is zero, so this method incorrect detect error as NoError.
This reset errno is due to the fact that between calls to read() and
decodeSystemError(), there are other system calls that are implemented
within QRingBuffer (e.g. access to memory).
Therefore, must do decodeSystemError() immediately after the failed
I/O calls, so need to move decodeSystemError() near to I/O calls.
Change-Id: Iad7e78247cf81a0a6ed5053ee996728881414558
Reviewed-by: Laszlo Papp <lpapp@kde.org>
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index d0e31de7..64bfcfb6 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -706,11 +706,6 @@ bool QSerialPortPrivate::readNotification() if (readBytes <= 0) { readBuffer.chop(bytesToRead); - - QSerialPort::SerialPortError error = decodeSystemError(); - if (error != QSerialPort::ResourceError) - error = QSerialPort::ReadError; - q_ptr->setError(error); return false; } @@ -759,13 +754,8 @@ bool QSerialPortPrivate::writeNotification(int maxSize) // Attempt to write it chunk. qint64 written = writeToPort(ptr, nextSize); - if (written < 0) { - QSerialPort::SerialPortError error = decodeSystemError(); - if (error != QSerialPort::ResourceError) - error = QSerialPort::WriteError; - q_ptr->setError(error); + if (written < 0) return false; - } // Remove what we wrote so far. writeBuffer.free(written); @@ -1021,6 +1011,13 @@ qint64 QSerialPortPrivate::readFromPort(char *data, qint64 maxSize) bytesRead = readPerChar(data, maxSize); } + if (bytesRead <= 0) { + QSerialPort::SerialPortError error = decodeSystemError(); + if (error != QSerialPort::ResourceError) + error = QSerialPort::ReadError; + q_ptr->setError(error); + } + return bytesRead; } @@ -1038,6 +1035,13 @@ qint64 QSerialPortPrivate::writeToPort(const char *data, qint64 maxSize) } #endif + if (bytesWritten < 0) { + QSerialPort::SerialPortError error = decodeSystemError(); + if (error != QSerialPort::ResourceError) + error = QSerialPort::WriteError; + q_ptr->setError(error); + } + return bytesWritten; } |