summaryrefslogtreecommitdiffstats
path: root/src/serialport/qserialport_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/serialport/qserialport_unix.cpp')
-rw-r--r--src/serialport/qserialport_unix.cpp64
1 files changed, 17 insertions, 47 deletions
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index 294782b5..7e642e57 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -1,47 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
-** Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
-** Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de>
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSerialPort module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2012 Denis Shienkov <denis.shienkov@gmail.com>
+// Copyright (C) 2012 Laszlo Papp <lpapp@kde.org>
+// Copyright (C) 2012 Andre Hartmann <aha_1980@gmx.de>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qserialport_p.h"
#include "qserialportinfo_p.h"
+#include <QtCore/qdeadlinetimer.h>
#include <QtCore/qelapsedtimer.h>
#include <QtCore/qmap.h>
#include <QtCore/qsocketnotifier.h>
@@ -55,7 +20,7 @@
#include <sys/time.h>
#include <unistd.h>
-#ifdef Q_OS_OSX
+#ifdef Q_OS_MACOS
#if defined(MAC_OS_X_VERSION_10_4) && (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4)
#include <IOKit/serial/ioss.h>
#endif
@@ -316,7 +281,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
return false;
}
- QScopedPointer<QLockFile> newLockFileScopedPointer(new QLockFile(lockFilePath));
+ auto newLockFileScopedPointer = std::make_unique<QLockFile>(lockFilePath);
if (!newLockFileScopedPointer->tryLock()) {
setError(QSerialPortErrorInfo(QSerialPort::PermissionError, QSerialPort::tr("Permission error while locking the device")));
@@ -349,7 +314,7 @@ bool QSerialPortPrivate::open(QIODevice::OpenMode mode)
return false;
}
- lockFileScopedPointer.swap(newLockFileScopedPointer);
+ lockFileScopedPointer = std::move(newLockFileScopedPointer);
return true;
}
@@ -650,7 +615,7 @@ bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directi
return setStandardBaudRate(B38400, directions);
}
-#elif defined(Q_OS_OSX)
+#elif defined(Q_OS_MACOS)
bool QSerialPortPrivate::setCustomBaudRate(qint32 baudRate, QSerialPort::Directions directions)
{
@@ -786,7 +751,7 @@ bool QSerialPortPrivate::readNotification()
buffer.chop(bytesToRead - qMax(readBytes, qint64(0)));
- if (readBytes <= 0) {
+ if (readBytes < 0) {
QSerialPortErrorInfo error = getSystemError();
if (error.errorCode != QSerialPort::ResourceError)
error.errorCode = QSerialPort::ReadError;
@@ -794,6 +759,8 @@ bool QSerialPortPrivate::readNotification()
setReadNotificationEnabled(false);
setError(error);
return false;
+ } else if (readBytes == 0) {
+ return false;
}
newBytes = buffer.size() - newBytes;
@@ -885,6 +852,9 @@ inline bool QSerialPortPrivate::initialize(QIODevice::OpenMode mode)
if (mode & QIODevice::ReadOnly)
setReadNotificationEnabled(true);
+ // flush IO buffers
+ clear(QSerialPort::AllDirections);
+
return true;
}
@@ -947,7 +917,7 @@ QSerialPortErrorInfo QSerialPortPrivate::getSystemError(int systemErrorCode) con
case EBADF:
error.errorCode = QSerialPort::ResourceError;
break;
-#ifdef Q_OS_OSX
+#ifdef Q_OS_MACOS
case ENXIO:
error.errorCode = QSerialPort::ResourceError;
break;
@@ -1028,7 +998,7 @@ bool QSerialPortPrivate::waitForReadOrWrite(bool *selectForRead, bool *selectFor
if (checkWrite)
pfd.events |= POLLOUT;
- const int ret = qt_poll_msecs(&pfd, 1, msecs);
+ const int ret = qt_safe_poll(&pfd, 1, QDeadlineTimer(msecs));
if (ret < 0) {
setError(getSystemError());
return false;