diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-12-03 17:54:44 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-12-10 21:10:05 +0000 |
commit | f7fd9394e54087498103f091a308375cf5586a00 (patch) | |
tree | d3d8e507aa0c58ec84957bc43353f1c51a437301 | |
parent | ee8b6b206dc1c14393d96516beae54b6ae49dd2e (diff) | |
download | qtconnectivity-f7fd9394e54087498103f091a308375cf5586a00.tar.gz |
Windows QBluetoothSocket: remove unneeded variable from SocketWorker
The m_initialReadOp member of the SocketWorker class is used only once,
to perform initial read. After that m_readOp is used for all other
reads.
I see no reason why we need a separate variable for the first read, so
this patch uses m_readOp instead. This allows to simplify the code by
removing some duplication.
Change-Id: If4dd57c9f080d90c975cef676c1bf84cedf44178
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 54a856d8f654fb6183c772b4eaacd92703d22062)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/bluetooth/qbluetoothsocket_winrt.cpp | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index dcd4f39e..380b9d69 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -136,20 +136,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; @@ -187,9 +173,9 @@ public: ComPtr<IInputStream> stream; hr = m_socket->get_InputStream(&stream); Q_ASSERT_SUCCEEDED(hr); - hr = stream->ReadAsync(tempBuffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, m_initialReadOp.GetAddressOf()); + hr = stream->ReadAsync(tempBuffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, m_readOp.GetAddressOf()); Q_ASSERT_SUCCEEDED(hr); - hr = m_initialReadOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get()); + hr = m_readOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &SocketWorker::onReadyRead).Get()); Q_ASSERT_SUCCEEDED(hr); } @@ -198,13 +184,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 @@ -308,7 +291,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; }; |