diff options
author | Andreas Buhr <andreas@andreasbuhr.de> | 2021-02-11 10:44:11 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-12 19:38:39 +0000 |
commit | e61994ab9d82470fe15f4476eecf2aef1d570f35 (patch) | |
tree | 80967a452a724dcc4f62859f20e5c1ca94c25dbc | |
parent | b7a2cc8339335f2888186f8a179ccbe859f6f2af (diff) |
Fix error handling in BlueZ connectToServiceHelper
QBluetoothSocketPrivateBluezDBus uses asynchronous calls,
then blocking waits for the result and then does error handling.
The blocking wait was missed in one place, rendering the following
error handling code dysfunctional.
This patch adds the required blocking wait.
Fixes: QTBUG-82407
Change-Id: Ia45372e3b6cce3617d6c985fe1800a33631bc0fc
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
(cherry picked from commit 7aa19c8a512fdceac12cf4ee6587626e3de61c25)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluezdbus.cpp | 21 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluezdbus_p.h | 4 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp index f56abfba..3ce7e8b6 100644 --- a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp +++ b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp @@ -238,18 +238,29 @@ void QBluetoothSocketPrivateBluezDBus::connectToServiceHelper( OrgBluezDevice1Interface device(QStringLiteral("org.bluez"), remoteDevicePath, QDBusConnection::systemBus()); reply = device.ConnectProfile(profileUuid); + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + connect(watcher, &QDBusPendingCallWatcher::finished, + this, &QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler); + + q->setOpenMode(openMode); + q->setSocketState(QBluetoothSocket::ConnectingState); +} + +void QBluetoothSocketPrivateBluezDBus::connectToServiceReplyHandler( + QDBusPendingCallWatcher *watcher) +{ + Q_Q(QBluetoothSocket); + + QDBusPendingReply<> reply = *watcher; if (reply.isError()) { - qCWarning(QT_BT_BLUEZ) << "Cannot connect to profile/service:" << uuid; + qCWarning(QT_BT_BLUEZ) << "Cannot connect to profile/service."; clearSocket(); errorString = QBluetoothSocket::tr("Cannot connect to remote profile"); q->setSocketError(QBluetoothSocket::HostNotFoundError); - return; } - - q->setOpenMode(openMode); - q->setSocketState(QBluetoothSocket::ConnectingState); + watcher->deleteLater(); } void QBluetoothSocketPrivateBluezDBus::connectToService( diff --git a/src/bluetooth/qbluetoothsocket_bluezdbus_p.h b/src/bluetooth/qbluetoothsocket_bluezdbus_p.h index 383c9fcb..deedf916 100644 --- a/src/bluetooth/qbluetoothsocket_bluezdbus_p.h +++ b/src/bluetooth/qbluetoothsocket_bluezdbus_p.h @@ -56,6 +56,7 @@ #include <QtDBus/qdbusunixfiledescriptor.h> #include <QtNetwork/qlocalsocket.h> +#include <QDBusPendingCallWatcher> class OrgBluezProfileManager1Interface; @@ -110,6 +111,9 @@ public: bool canReadLine() const override; qint64 bytesToWrite() const override; +public slots: + void connectToServiceReplyHandler(QDBusPendingCallWatcher *); + private: void remoteConnected(const QDBusUnixFileDescriptor &fd); void socketStateChanged(QLocalSocket::LocalSocketState newState); |