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:16 +0000
commite1f29814daf1ea81b05cc95cc5d187eea362af67 (patch)
treed19bfe10565bf0423d549a7393364cd68dce9693 /src/network/socket/qnativesocketengine_winrt.cpp
parent71166288cb71b58eb7a84b70e92a10396cdf9ee4 (diff)
winrt: Proper guarding by readMutex
Commented its purpose and the guarded members for readMutex. Fixed places where guarded members were accessed without using the mutex. Use QMutexLocker instead of manually (un-)locking the mutex. Task-number: QTBUG-44357 Change-Id: I0d46f9592d5a9d1b52e73df961785a6f6c9e80be 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.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp
index f8e92d3f50..f710f6b142 100644
--- a/src/network/socket/qnativesocketengine_winrt.cpp
+++ b/src/network/socket/qnativesocketengine_winrt.cpp
@@ -659,6 +659,7 @@ qint64 QNativeSocketEngine::read(char *data, qint64 maxlen)
if (d->socketType != QAbstractSocket::TcpSocket)
return -1;
+ QMutexLocker mutexLocker(&d->readMutex);
// There will be a read notification when the socket was closed by the remote host. If that
// happens and there isn't anything left in the buffer, we have to return -1 in order to signal
// the closing of the socket.
@@ -667,7 +668,6 @@ qint64 QNativeSocketEngine::read(char *data, qint64 maxlen)
return -1;
}
- QMutexLocker mutexLocker(&d->readMutex);
qint64 b = d->readBytes.read(data, maxlen);
d->bytesAvailable = d->readBytes.size() - d->readBytes.pos();
return b;
@@ -701,7 +701,7 @@ qint64 QNativeSocketEngine::readDatagram(char *data, qint64 maxlen, QIpPacketHea
{
#ifndef QT_NO_UDPSOCKET
Q_D(QNativeSocketEngine);
- d->readMutex.lock();
+ QMutexLocker locker(&d->readMutex);
if (d->socketType != QAbstractSocket::UdpSocket || d->pendingDatagrams.isEmpty()) {
if (header)
header->clear();
@@ -721,7 +721,7 @@ qint64 QNativeSocketEngine::readDatagram(char *data, qint64 maxlen, QIpPacketHea
} else {
readOrigin = datagram.data;
}
- d->readMutex.unlock();
+ locker.unlock();
memcpy(data, readOrigin, qMin(maxlen, qint64(datagram.data.length())));
return readOrigin.length();
#else
@@ -772,12 +772,14 @@ qint64 QNativeSocketEngine::writeDatagram(const char *data, qint64 len, const QI
bool QNativeSocketEngine::hasPendingDatagrams() const
{
Q_D(const QNativeSocketEngine);
+ QMutexLocker locker(&d->readMutex);
return d->pendingDatagrams.length() > 0;
}
qint64 QNativeSocketEngine::pendingDatagramSize() const
{
Q_D(const QNativeSocketEngine);
+ QMutexLocker locker(&d->readMutex);
if (d->pendingDatagrams.isEmpty())
return -1;
@@ -1465,7 +1467,7 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
hr = byteArrayAccess->Buffer(&data);
Q_ASSERT_SUCCEEDED(hr);
- readMutex.lock();
+ QMutexLocker readLocker(&readMutex);
if (readBytes.atEnd()) // Everything has been read; the buffer is safe to reset
readBytes.close();
if (!readBytes.isOpen())
@@ -1476,7 +1478,7 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
readBytes.write(reinterpret_cast<const char*>(data), qint64(bufferLength));
readBytes.seek(readPos);
bytesAvailable = readBytes.size() - readBytes.pos();
- readMutex.unlock();
+ readLocker.unlock();
if (notifyOnRead)
emit q->readReady();