summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2017-05-30 14:39:50 +0200
committerOliver Wolff <oliver.wolff@qt.io>2017-06-02 12:30:25 +0000
commit91ef71b7bf3526a0bb7f6f83e6b3e03e286c2030 (patch)
treeb4d9e75b6992da250315a8466a3fa3c9a8ef24d6
parent8c620d24bb220fd3db32a75023b892b26fad32f3 (diff)
winrt: Get rid of one deferral when handling socket data
Instead of defering one more time by emitting the signal, we can add the data to the list of available data/pending datagrams. For TCP readNotification can be invoked directly so that emission of the readyRead signal is tightly coupled to the availability of new data. For UDP sockets calling readNotification directly stops handling of more data and thus cannot be done. With the old approach it was possible, that the last bit of TCP data was lost, because the socket was closed while the data was still being processed/transferred from the worker to the engine. Task-number: QTBUG-61078 Change-Id: I9330b87876be853d310dc9e8e817ab344939d5dd Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
-rw-r--r--src/network/socket/qnativesocketengine_winrt.cpp37
-rw-r--r--src/network/socket/qnativesocketengine_winrt_p.h3
2 files changed, 10 insertions, 30 deletions
diff --git a/src/network/socket/qnativesocketengine_winrt.cpp b/src/network/socket/qnativesocketengine_winrt.cpp
index 0625ea65da..38c2b6e8c0 100644
--- a/src/network/socket/qnativesocketengine_winrt.cpp
+++ b/src/network/socket/qnativesocketengine_winrt.cpp
@@ -1250,20 +1250,22 @@ void QNativeSocketEngine::handleConnectOpFinished(bool success, QAbstractSocket:
void QNativeSocketEngine::handleNewDatagrams(const QList<WinRtDatagram> &datagrams)
{
Q_D(QNativeSocketEngine);
- // Defer putting the datagrams into the list until the next event loop iteration
- // (where the readyRead signal is emitted as well)
- QMetaObject::invokeMethod(this, "putIntoPendingDatagramsList", Qt::QueuedConnection,
- Q_ARG(QList<WinRtDatagram>, datagrams));
+ QMutexLocker locker(&d->readMutex);
+ d->pendingDatagrams.append(datagrams);
if (d->notifyOnRead)
emit readReady();
}
void QNativeSocketEngine::handleNewData(const QVector<QByteArray> &data)
{
- // Defer putting the data into the list until the next event loop iteration
- // (where the readyRead signal is emitted as well)
- QMetaObject::invokeMethod(this, "putIntoPendingData", Qt::QueuedConnection,
- Q_ARG(QVector<QByteArray>, data));
+ Q_D(QNativeSocketEngine);
+ QMutexLocker locker(&d->readMutex);
+ d->pendingData.append(data);
+ for (const QByteArray &newData : data)
+ d->bytesAvailable += newData.length();
+ locker.unlock();
+ if (d->notifyOnRead)
+ readNotification();
}
void QNativeSocketEngine::handleTcpError(QAbstractSocket::SocketError error)
@@ -1284,25 +1286,6 @@ void QNativeSocketEngine::handleTcpError(QAbstractSocket::SocketError error)
emit readReady();
}
-void QNativeSocketEngine::putIntoPendingDatagramsList(const QList<WinRtDatagram> &datagrams)
-{
- Q_D(QNativeSocketEngine);
- QMutexLocker locker(&d->readMutex);
- d->pendingDatagrams.append(datagrams);
-}
-
-void QNativeSocketEngine::putIntoPendingData(const QVector<QByteArray> &data)
-{
- Q_D(QNativeSocketEngine);
- QMutexLocker locker(&d->readMutex);
- d->pendingData.append(data);
- for (const QByteArray &newData : data)
- d->bytesAvailable += newData.length();
- locker.unlock();
- if (d->notifyOnRead)
- readNotification();
-}
-
bool QNativeSocketEnginePrivate::createNewSocket(QAbstractSocket::SocketType socketType, QAbstractSocket::NetworkLayerProtocol &socketProtocol)
{
Q_UNUSED(socketProtocol);
diff --git a/src/network/socket/qnativesocketengine_winrt_p.h b/src/network/socket/qnativesocketengine_winrt_p.h
index 6528c6d627..13922cb397 100644
--- a/src/network/socket/qnativesocketengine_winrt_p.h
+++ b/src/network/socket/qnativesocketengine_winrt_p.h
@@ -183,9 +183,6 @@ private slots:
void handleTcpError(QAbstractSocket::SocketError error);
private:
- Q_INVOKABLE void putIntoPendingDatagramsList(const QList<WinRtDatagram> &datagrams);
- Q_INVOKABLE void putIntoPendingData(const QVector<QByteArray> &data);
-
Q_DECLARE_PRIVATE(QNativeSocketEngine)
Q_DISABLE_COPY(QNativeSocketEngine)
};