From 52a03bcb3cad602175062456aca15ae9a16f6006 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Fri, 3 Dec 2021 17:54:44 +0100 Subject: 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 (cherry picked from commit 54a856d8f654fb6183c772b4eaacd92703d22062) Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket_winrt.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index f542829b..731d5432 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -141,20 +141,6 @@ public: void close() { m_shuttingDown = true; - if (Q_UNLIKELY(m_initialReadOp)) { - onReadyRead(m_initialReadOp.Get(), Canceled); - ComPtr 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 info; @@ -195,9 +181,9 @@ public: ComPtr 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(this, &SocketWorker::onReadyRead).Get()); + hr = m_readOp->put_Completed(Callback(this, &SocketWorker::onReadyRead).Get()); Q_ASSERT_SUCCEEDED(hr); return S_OK; }); @@ -209,13 +195,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 @@ -323,7 +306,6 @@ private: // Protects pendingData/pendingDatagrams which are accessed from native callbacks QMutex m_mutex; - ComPtr> m_initialReadOp; ComPtr> m_readOp; }; -- cgit v1.2.3