From be5af68f8194ab0c59ca3f4a5bcafd3c71100b52 Mon Sep 17 00:00:00 2001
From: Alex Blasche <alexander.blasche@qt.io>
Date: Fri, 7 Jul 2017 10:47:21 +0200
Subject: [PATCH] Add support for QBluetoothSocket::RemoteHostClosedError on
 BlueZ

Change-Id: I88ff16001280dea4967887ae711c463304c7ec7d
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
---
 src/bluetooth/qbluetoothsocket_bluez.cpp     | 4 +++-
 src/bluetooth/qlowenergycontroller_bluez.cpp | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp
index 6aef811a..17b8e738 100644
--- a/src/bluetooth/qbluetoothsocket_bluez.cpp
+++ b/src/bluetooth/qbluetoothsocket_bluez.cpp
@@ -290,7 +290,9 @@ void QBluetoothSocketPrivate::_q_readNotify()
         qCWarning(QT_BT_BLUEZ) << Q_FUNC_INFO << socket << "error:" << readFromDevice << errorString;
         if (errsv == EHOSTDOWN)
             q->setSocketError(QBluetoothSocket::HostNotFoundError);
-        else if (errsv != ECONNRESET) // The other side closing the connection is not an error.
+        else if (errsv == ECONNRESET)
+            q->setSocketError(QBluetoothSocket::RemoteHostClosedError);
+        else
             q->setSocketError(QBluetoothSocket::UnknownSocketError);
 
         q->disconnectFromService();
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 0744bcc4..8eee2ab2 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -753,6 +753,10 @@ void QLowEnergyControllerPrivate::l2cpErrorChanged(QBluetoothSocket::SocketError
         setError(QLowEnergyController::NetworkError);
         qCDebug(QT_BT_BLUEZ) << "Network IO error while talking to LE device";
         break;
+    case QBluetoothSocket::RemoteHostClosedError:
+        setError(QLowEnergyController::RemoteHostClosedError);
+        qCDebug(QT_BT_BLUEZ) << "Remote host closed the connection";
+        break;
     case QBluetoothSocket::UnknownSocketError:
     case QBluetoothSocket::UnsupportedProtocolError:
     case QBluetoothSocket::OperationError:
-- 
GitLab