summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothsocket_winrt.cpp
diff options
context:
space:
mode:
authorTarja Sundqvist <tarja.sundqvist@qt.io>2023-03-23 21:57:01 +0200
committerTarja Sundqvist <tarja.sundqvist@qt.io>2023-03-23 21:57:01 +0200
commit3dcb548bd6fe4aa488ca0bac95e65a7a366c3eca (patch)
treed8e263e0341880d970832326c7c7cecfd05e67cd /src/bluetooth/qbluetoothsocket_winrt.cpp
parente957d4810b05d8453e163d7bcdcab42d3c60a7bb (diff)
parent2b3b5c899ebdb0fc11273af7370804f5f03ad9e8 (diff)
Merge remote-tracking branch 'origin/tqtc/lts-5.15.9' into tqtc/lts-5.15-opensourcev5.15.9-lts-lgpl
Diffstat (limited to 'src/bluetooth/qbluetoothsocket_winrt.cpp')
-rw-r--r--src/bluetooth/qbluetoothsocket_winrt.cpp43
1 files changed, 20 insertions, 23 deletions
diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp
index d562f6f7..e7a42f01 100644
--- a/src/bluetooth/qbluetoothsocket_winrt.cpp
+++ b/src/bluetooth/qbluetoothsocket_winrt.cpp
@@ -50,6 +50,7 @@
#include <QtBluetooth/qbluetoothdeviceinfo.h>
#include <QtBluetooth/qbluetoothserviceinfo.h>
#include <QtCore/qloggingcategory.h>
+#include <QtCore/QPointer>
#include <robuffer.h>
#include <windows.devices.bluetooth.h>
@@ -141,20 +142,6 @@ 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);
- if (info) {
- hr = info->Cancel();
- Q_ASSERT_SUCCEEDED(hr);
- hr = info->Close();
- Q_ASSERT_SUCCEEDED(hr);
- }
- m_initialReadOp.Reset();
- }
-
if (m_readOp) {
onReadyRead(m_readOp.Get(), Canceled);
ComPtr<IAsyncInfo> info;
@@ -195,9 +182,16 @@ public:
ComPtr<IInputStream> stream;
hr = m_socket->get_InputStream(&stream);
Q_ASSERT_SUCCEEDED(hr);
- hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, m_initialReadOp.GetAddressOf());
+ hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, m_readOp.GetAddressOf());
Q_ASSERT_SUCCEEDED(hr);
- hr = m_initialReadOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get());
+ QPointer<SocketWorker> thisPtr(this);
+ hr = m_readOp->put_Completed(
+ Callback<SocketReadCompletedHandler>([thisPtr](IAsyncBufferOperation *asyncInfo,
+ AsyncStatus status) {
+ if (thisPtr)
+ return thisPtr->onReadyRead(asyncInfo, status);
+ return S_OK;
+ }).Get());
Q_ASSERT_SUCCEEDED(hr);
return S_OK;
});
@@ -209,13 +203,10 @@ public:
if (m_shuttingDown)
return S_OK;
- if (asyncInfo == m_initialReadOp.Get()) {
- m_initialReadOp.Reset();
- } else if (asyncInfo == m_readOp.Get()) {
+ if (asyncInfo == m_readOp.Get())
m_readOp.Reset();
- } else {
+ else
Q_ASSERT(false);
- }
// A read in UnconnectedState will close the socket and return -1 and thus tell the caller,
// that the connection was closed. The socket cannot be closed here, as the subsequent read
@@ -301,7 +292,14 @@ public:
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
return S_OK;
}
- hr = m_readOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get());
+ QPointer<SocketWorker> thisPtr(this);
+ hr = m_readOp->put_Completed(
+ Callback<SocketReadCompletedHandler>([thisPtr](IAsyncBufferOperation *asyncInfo,
+ AsyncStatus status) {
+ if (thisPtr)
+ return thisPtr->onReadyRead(asyncInfo, status);
+ return S_OK;
+ }).Get());
if (FAILED(hr)) {
qErrnoWarning(hr, "onReadyRead(): Failed to set socket read callback.");
emit socketErrorOccured(QBluetoothSocket::UnknownSocketError);
@@ -323,7 +321,6 @@ private:
// Protects pendingData/pendingDatagrams which are accessed from native callbacks
QMutex m_mutex;
- ComPtr<IAsyncOperationWithProgress<IBuffer *, UINT32>> m_initialReadOp;
ComPtr<IAsyncOperationWithProgress<IBuffer *, UINT32>> m_readOp;
};