diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2021-12-03 17:54:44 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2021-12-14 15:30:15 +0100 |
commit | 52a03bcb3cad602175062456aca15ae9a16f6006 (patch) | |
tree | 1ba9897b09bfb276746c8eb84f716d8d2d167d9d | |
parent | d8473c74e16e2e1d99b97894616ca9a0cd0662c9 (diff) |
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: Alex Blasche <alexander.blasche@qt.io>
-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 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<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 +181,9 @@ 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()); + hr = m_readOp->put_Completed(Callback<SocketReadCompletedHandler>(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<IAsyncOperationWithProgress<IBuffer *, UINT32>> m_initialReadOp; ComPtr<IAsyncOperationWithProgress<IBuffer *, UINT32>> m_readOp; }; |