diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-02-11 13:16:12 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-12 06:11:19 +0100 |
commit | a8597cbae47076e33b638c2e593f852c8c0a02d5 (patch) | |
tree | 8b202ef873cc73c9037ec28404974649af827acf | |
parent | 691212d9e492b12590d5b7f4e2b24921911d4b17 (diff) | |
download | qtserialport-a8597cbae47076e33b638c2e593f852c8c0a02d5.tar.gz |
Protect against EINTR in Unix non-atomic I/O calls
read(), write() and close() may return EINTR, indicating the system call
should be restarted. The qt_safe_xxx versions of those functions do it.
Change-Id: Ifef3b98131a7e24a5defea3e3af9345a505ad733
Reviewed-by: Laszlo Papp <lpapp@kde.org>
-rw-r--r-- | src/serialport/qserialport_unix.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp index a788b4d..84f3109 100644 --- a/src/serialport/qserialport_unix.cpp +++ b/src/serialport/qserialport_unix.cpp @@ -306,7 +306,7 @@ void QSerialPortPrivate::close() exceptionNotifier = 0; } - if (::close(descriptor) == -1) + if (qt_safe_close(descriptor) == -1) q->setError(decodeSystemError()); if (lockFileScopedPointer->isLocked()) @@ -1078,7 +1078,7 @@ qint64 QSerialPortPrivate::readFromPort(char *data, qint64 maxSize) if (parity != QSerialPort::MarkParity && parity != QSerialPort::SpaceParity) { #endif - bytesRead = ::read(descriptor, data, maxSize); + bytesRead = qt_safe_read(descriptor, data, maxSize); } else {// Perform parity emulation. bytesRead = readPerChar(data, maxSize); } @@ -1090,11 +1090,11 @@ qint64 QSerialPortPrivate::writeToPort(const char *data, qint64 maxSize) { qint64 bytesWritten = 0; #if defined (CMSPAR) - bytesWritten = ::write(descriptor, data, maxSize); + bytesWritten = qt_safe_write(descriptor, data, maxSize); #else if (parity != QSerialPort::MarkParity && parity != QSerialPort::SpaceParity) { - bytesWritten = ::write(descriptor, data, maxSize); + bytesWritten = qt_safe_write(descriptor, data, maxSize); } else {// Perform parity emulation. bytesWritten = writePerChar(data, maxSize); } @@ -1131,7 +1131,7 @@ qint64 QSerialPortPrivate::writePerChar(const char *data, qint64 maxSize) break; } - int r = ::write(descriptor, data, 1); + int r = qt_safe_write(descriptor, data, 1); if (r < 0) return -1; if (r > 0) { @@ -1157,7 +1157,7 @@ qint64 QSerialPortPrivate::readPerChar(char *data, qint64 maxSize) int prefix = 0; while (ret < maxSize) { - qint64 r = ::read(descriptor, data, 1); + qint64 r = qt_safe_read(descriptor, data, 1); if (r < 0) { if (errno == EAGAIN) // It is ok for nonblocking mode. break; |