summaryrefslogtreecommitdiffstats
path: root/src/network/socket/qnativesocketengine_winrt_p.h
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2016-11-30 15:32:02 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-06 07:59:39 +0000
commit14ea8759da0d5eb1888664a5b0d08c2bf142a6a2 (patch)
treec09adf6141fba1273d58fb4d2d07e1182a64544e /src/network/socket/qnativesocketengine_winrt_p.h
parent6ae9dc3f379728a1aaee818a169c03954d6a445c (diff)
winrt: Change the way tcp packets are handled
Similar to the way datagrams are handled for udp sockets the worker now takes care of tcp data. Thus we avoid race conditions which stopped data processing. It could happen that data was read from the socket into the buffer and before readyRead was emitted the buffer was completely read. In this case readNotification is set to false and no new data is processed afterwards. Additionally the buffer was replaced by a vector of QByteArray. The buffer kept growing and was never cleared (and there is no obvious way for clearing the buffer), so that an overflow happened eventually. pendingReadOperations (and its mutex) could be removed as well. There is only one situation where they could clash and that's the initial read. Having two members is preferred over having a list of operations and a mutex. Task-number: QTBUG-56438 Change-Id: Idbad58e47785996023748c310530892163f24594 Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'src/network/socket/qnativesocketengine_winrt_p.h')
-rw-r--r--src/network/socket/qnativesocketengine_winrt_p.h16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/network/socket/qnativesocketengine_winrt_p.h b/src/network/socket/qnativesocketengine_winrt_p.h
index 085704275c..9758310902 100644
--- a/src/network/socket/qnativesocketengine_winrt_p.h
+++ b/src/network/socket/qnativesocketengine_winrt_p.h
@@ -144,9 +144,12 @@ signals:
private slots:
void establishRead();
void handleNewDatagrams(const QList<WinRtDatagram> &datagram);
+ void handleNewData(const QVector<QByteArray> &data);
+ 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)
@@ -215,23 +218,17 @@ private:
Microsoft::WRL::ComPtr<ABI::Windows::Networking::Sockets::IStreamSocketListener> tcpListener;
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncAction> connectOp;
- // Protected by readOperationsMutex. Written in handleReadyRead (native callback)
- QVector<Microsoft::WRL::ComPtr<ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer *, UINT32>>> pendingReadOps;
-
- // Protected by readMutex. Written in handleReadyRead (native callback)
- QBuffer readBytes;
-
// In case of TCP readMutex protects readBytes and bytesAvailable. In case of UDP it is
// pendingDatagrams. They are written inside native callbacks (handleReadyRead and
// handleNewDatagrams/putIntoPendingDatagramsList)
mutable QMutex readMutex;
- // As pendingReadOps is changed inside handleReadyRead(native callback) it has to be protected
- QMutex readOperationsMutex;
-
// Protected by readMutex. Written in handleReadyRead (native callback)
QAtomicInteger<int> bytesAvailable;
+ // Protected by readMutex. Written in handleNewData/putIntoPendingData (native callback)
+ QVector<QByteArray> pendingData;
+
// Protected by readMutex. Written in handleNewDatagrams/putIntoPendingDatagramsList
QList<WinRtDatagram> pendingDatagrams;
@@ -246,7 +243,6 @@ private:
HRESULT handleClientConnection(ABI::Windows::Networking::Sockets::IStreamSocketListener *tcpListener,
ABI::Windows::Networking::Sockets::IStreamSocketListenerConnectionReceivedEventArgs *args);
HRESULT handleConnectOpFinished(ABI::Windows::Foundation::IAsyncAction *, ABI::Windows::Foundation::AsyncStatus);
- HRESULT handleReadyRead(ABI::Windows::Foundation::IAsyncOperationWithProgress<ABI::Windows::Storage::Streams::IBuffer *, UINT32> *asyncInfo, ABI::Windows::Foundation::AsyncStatus);
};
QT_END_NAMESPACE