From b80ed337cb3a145038ad6384df3bfcce8134a0e7 Mon Sep 17 00:00:00 2001
From: Alex Blasche <alexander.blasche@qt.io>
Date: Thu, 6 Jul 2017 12:37:28 +0200
Subject: [PATCH] Add error flag for use case when the remote peer closes the
 connection

[ChangeLog][QtBluetooth][QBluetoothSocket] Added
QBluetoothSocket::RemoteHostClosedError.

Change-Id: Ic9d27f9188f66be0fad309e55f2904eaed2cf61a
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
---
 src/bluetooth/qbluetoothsocket.cpp                    | 5 +++++
 src/bluetooth/qbluetoothsocket.h                      | 1 +
 src/bluetooth/qbluetoothsocket_osx.mm                 | 3 +++
 src/imports/bluetooth/qdeclarativebluetoothsocket.cpp | 1 +
 src/imports/bluetooth/qdeclarativebluetoothsocket_p.h | 1 +
 5 files changed, 11 insertions(+)

diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp
index 2f38ed04..f8aa8ddf 100644
--- a/src/bluetooth/qbluetoothsocket.cpp
+++ b/src/bluetooth/qbluetoothsocket.cpp
@@ -112,6 +112,8 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT)
                                     supported on this platform.
     \value OperationError           An operation was attempted while the socket was in a state
                                     that did not permit it.
+    \value RemoteHostClosedError    The remote host closed the connection. This value was
+                                    introduced by Qt 5.10.
 */
 
 /*!
@@ -854,6 +856,9 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
     case QBluetoothSocket::HostNotFoundError:
         debug << "QBluetoothSocket::HostNotFoundError";
         break;
+    case QBluetoothSocket::RemoteHostClosedError:
+        debug << "QBluetoothSocket::RemoteHostClosedError";
+        break;
     case QBluetoothSocket::ServiceNotFoundError:
         debug << "QBluetoothSocket::ServiceNotFoundError";
         break;
diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h
index 97b6685b..2b1bd3cf 100644
--- a/src/bluetooth/qbluetoothsocket.h
+++ b/src/bluetooth/qbluetoothsocket.h
@@ -79,6 +79,7 @@ public:
     enum SocketError {
         NoSocketError = -2,
         UnknownSocketError = QAbstractSocket::UnknownSocketError, //-1
+        RemoteHostClosedError = QAbstractSocket::RemoteHostClosedError, //1
         HostNotFoundError = QAbstractSocket::HostNotFoundError, //2
         ServiceNotFoundError = QAbstractSocket::SocketAddressNotAvailableError, //9
         NetworkError = QAbstractSocket::NetworkError, //7
diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm
index 75712868..cde98720 100644
--- a/src/bluetooth/qbluetoothsocket_osx.mm
+++ b/src/bluetooth/qbluetoothsocket_osx.mm
@@ -761,6 +761,9 @@ QDebug operator<<(QDebug debug, QBluetoothSocket::SocketError error)
     case QBluetoothSocket::HostNotFoundError:
         debug << "QBluetoothSocket::HostNotFoundError";
         break;
+    case QBluetoothSocket::RemoteHostClosedError:
+        debug << "QBluetoothSocket::RemoteHostClosedError";
+        break;
     case QBluetoothSocket::ServiceNotFoundError:
         debug << "QBluetoothSocket::ServiceNotFoundError";
         break;
diff --git a/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp b/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp
index 7dbb1556..0d5a5eae 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothsocket.cpp
@@ -244,6 +244,7 @@ void QDeclarativeBluetoothSocket::setConnected(bool connected)
         \li \c{ServiceNotFoundError}
         \li \c{NetworkError}
         \li \c{UnsupportedProtocolError}
+        \li \c{RemoteHostClosedError}
     \endlist
 
     The errors are derived from \l QBluetoothSocket::SocketError. This property is read-only.
diff --git a/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h b/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h
index faa2c29c..e5092d2c 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h
+++ b/src/imports/bluetooth/qdeclarativebluetoothsocket_p.h
@@ -78,6 +78,7 @@ public:
     enum Error {
         NoError = QBluetoothSocket::NoSocketError,
         UnknownSocketError = QBluetoothSocket::UnknownSocketError,
+        RemoteHostClosedError = QBluetoothSocket::RemoteHostClosedError,
         HostNotFoundError = QBluetoothSocket::HostNotFoundError,
         ServiceNotFoundError = QBluetoothSocket::ServiceNotFoundError,
         NetworkError = QBluetoothSocket::NetworkError,
-- 
GitLab