summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2018-02-13 14:34:07 +0100
committerOliver Wolff <oliver.wolff@qt.io>2018-02-27 12:02:26 +0000
commit7f18a765d6e31bd3bd666eb965a8a36c021a8216 (patch)
tree44e1fc1ffb516866756de17d9461170b0af30f2d /src
parentd70fe2ac47dbf034991f0b2a4b0a3e1f16d171b9 (diff)
winrt: Properly close the bluetooth socket
If I understand the documentation correctly, the socket's onCompleted callback should be called manually (with a proper status) before calling Close on its read operation (see https://docs.microsoft.com/en-us/uwp/api/windows.foundation.iasyncoperationwithprogress_tresult_tprogress_). Additionally all logic could be cut from the callback as soon as shutdown is initiated as we might run into dangling pointers otherwise. Change-Id: I3b7969f1aae16c453bc450b652746c8e21b2ef8f Reviewed-by: Andre de la Rocha <andre.rocha@qt.io> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothsocket_winrt.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp
index 8fa1338f..670235fa 100644
--- a/src/bluetooth/qbluetoothsocket_winrt.cpp
+++ b/src/bluetooth/qbluetoothsocket_winrt.cpp
@@ -132,7 +132,9 @@ public:
}
void close()
{
+ m_shuttingDown = true;
if (Q_UNLIKELY(m_initialReadOp)) {
+ onReadyRead(m_initialReadOp.Get(), Canceled);
ComPtr<IAsyncInfo> info;
HRESULT hr = m_initialReadOp.As(&info);
Q_ASSERT_SUCCEEDED(hr);
@@ -142,9 +144,11 @@ public:
hr = info->Close();
Q_ASSERT_SUCCEEDED(hr);
}
+ m_initialReadOp.Reset();
}
if (m_readOp) {
+ onReadyRead(m_readOp.Get(), Canceled);
ComPtr<IAsyncInfo> info;
HRESULT hr = m_readOp.As(&info);
Q_ASSERT_SUCCEEDED(hr);
@@ -154,6 +158,7 @@ public:
hr = info->Close();
Q_ASSERT_SUCCEEDED(hr);
}
+ m_readOp.Reset();
}
}
@@ -193,6 +198,9 @@ public:
HRESULT onReadyRead(IAsyncBufferOperation *asyncInfo, AsyncStatus status)
{
+ if (m_shuttingDown)
+ return S_OK;
+
if (asyncInfo == m_initialReadOp.Get()) {
m_initialReadOp.Reset();
} else if (asyncInfo == m_readOp.Get()) {
@@ -302,6 +310,7 @@ public:
private:
ComPtr<IStreamSocket> m_socket;
QVector<QByteArray> m_pendingData;
+ bool m_shuttingDown = false;
// Protects pendingData/pendingDatagrams which are accessed from native callbacks
QMutex m_mutex;