summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_winrt.cpp
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2016-11-01 14:48:16 +0100
committerOliver Wolff <oliver.wolff@qt.io>2016-11-03 09:28:21 +0000
commitb787977ba0c266c157db9d0275e0fe9b7ae5d35f (patch)
treefe37f1f62d6a9ad2edfc5b8172d29bfff77bb047 /src/network/socket/qnativesocketengine_winrt.cpp
parente1f29814daf1ea81b05cc95cc5d187eea362af67 (diff)
winrt: Guard pendingReadOps with mutex
As the list is changed inside a native callback (handleReadyRead) which can be run inside another thread it has to be protected by a mutex. Change-Id: I145a866a36a12b7ea9bfa9f99ad9f7add872a021 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/network/socket/qnativesocketengine_winrt.cpp')
-rw-r--r--src/network/socket/qnativesocketengine_winrt.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp
index f710f6b142..7ea4d135f4 100644
--- a/src/network/socket/qnativesocketengine_winrt.cpp
+++ b/src/network/socket/qnativesocketengine_winrt.cpp
@@ -329,6 +329,7 @@ bool QNativeSocketEngine::initialize(qintptr socketDescriptor, QAbstractSocket::
hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, readOp.GetAddressOf());
RETURN_OK_IF_FAILED_WITH_ARGS("initialize(): Failed to read from the socket buffer (%s).",
socketDescription(this).constData());
+ QMutexLocker locker(&d->readOperationsMutex);
d->pendingReadOps.append(readOp);
d->socketState = socketState;
hr = readOp->put_Completed(Callback<SocketReadCompletedHandler>(d, &QNativeSocketEnginePrivate::handleReadyRead).Get());
@@ -574,6 +575,7 @@ void QNativeSocketEngine::close()
}
#endif // _MSC_VER >= 1900
+ QMutexLocker locker(&d->readOperationsMutex);
for (ComPtr<IAsyncBufferOperation> readOp : d->pendingReadOps) {
ComPtr<IAsyncInfo> info;
hr = readOp.As(&info);
@@ -585,6 +587,7 @@ void QNativeSocketEngine::close()
Q_ASSERT_SUCCEEDED(hr);
}
}
+ locker.unlock();
if (d->socketDescriptor != -1) {
ComPtr<IClosable> socket;
@@ -945,6 +948,7 @@ void QNativeSocketEngine::establishRead()
ComPtr<IAsyncBufferOperation> readOp;
hr = stream->ReadAsync(buffer.Get(), READ_BUFFER_SIZE, InputStreamOptions_Partial, readOp.GetAddressOf());
RETURN_HR_IF_FAILED("establishRead(): Failed to initiate socket read");
+ QMutexLocker locker(&d->readOperationsMutex);
d->pendingReadOps.append(readOp);
hr = readOp->put_Completed(Callback<SocketReadCompletedHandler>(d, &QNativeSocketEnginePrivate::handleReadyRead).Get());
RETURN_HR_IF_FAILED("establishRead(): Failed to register read callback");
@@ -1421,12 +1425,14 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
}
Q_Q(QNativeSocketEngine);
+ QMutexLocker locker(&readOperationsMutex);
for (int i = 0; i < pendingReadOps.count(); ++i) {
if (pendingReadOps.at(i).Get() == asyncInfo) {
pendingReadOps.takeAt(i);
break;
}
}
+ locker.unlock();
static QMutex mutex;
mutex.lock();
@@ -1503,6 +1509,7 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
socketDescription(q).constData());
return S_OK;
}
+ QMutexLocker locker(&readOperationsMutex);
pendingReadOps.append(readOp);
hr = readOp->put_Completed(Callback<SocketReadCompletedHandler>(this, &QNativeSocketEnginePrivate::handleReadyRead).Get());
if (FAILED(hr)) {