winrt: tcpsocket: Update bytesAvailable when new data is read
Instead of calculating the bytesAvailable in place, the value should be stored and only retrieved in the function itself. Otherwise it is possible that bytesAvailable is called between the data having been read and readyRead is emitted. In this case it's possible, that the client reads all the data before the signal is emitted. Triggering readyRead without any data being available will stop the socket. Task-number: QTBUG-44357 Change-Id: I81d6ab094c5fdd71f30b9ceba9d790153cc92439 Reviewed-by: Harald Meyer <dev@meh.at> Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
parent
19cbe171c2
commit
05fd7f8d90
@ -643,7 +643,7 @@ qint64 QNativeSocketEngine::bytesAvailable() const
|
||||
if (d->socketType != QAbstractSocket::TcpSocket)
|
||||
return -1;
|
||||
|
||||
return d->readBytes.size() - d->readBytes.pos();
|
||||
return d->bytesAvailable;
|
||||
}
|
||||
|
||||
qint64 QNativeSocketEngine::read(char *data, qint64 maxlen)
|
||||
@ -661,7 +661,9 @@ qint64 QNativeSocketEngine::read(char *data, qint64 maxlen)
|
||||
}
|
||||
|
||||
QMutexLocker mutexLocker(&d->readMutex);
|
||||
return d->readBytes.read(data, maxlen);
|
||||
qint64 b = d->readBytes.read(data, maxlen);
|
||||
d->bytesAvailable = d->readBytes.size() - d->readBytes.pos();
|
||||
return b;
|
||||
}
|
||||
|
||||
qint64 QNativeSocketEngine::write(const char *data, qint64 len)
|
||||
@ -1456,6 +1458,7 @@ HRESULT QNativeSocketEnginePrivate::handleReadyRead(IAsyncBufferOperation *async
|
||||
Q_ASSERT(readBytes.atEnd());
|
||||
readBytes.write(reinterpret_cast<const char*>(data), qint64(bufferLength));
|
||||
readBytes.seek(readPos);
|
||||
bytesAvailable = readBytes.size() - readBytes.pos();
|
||||
readMutex.unlock();
|
||||
|
||||
if (notifyOnRead)
|
||||
|
@ -55,6 +55,7 @@
|
||||
#include <QtCore/QEventLoop>
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QAtomicInteger>
|
||||
#include "QtNetwork/qhostaddress.h"
|
||||
#include "private/qabstractsocketengine_p.h"
|
||||
#include <wrl.h>
|
||||
@ -217,6 +218,7 @@ private:
|
||||
QBuffer readBytes;
|
||||
QMutex readMutex;
|
||||
bool emitOnNewDatagram;
|
||||
QAtomicInteger<int> bytesAvailable;
|
||||
|
||||
QList<WinRtDatagram> pendingDatagrams;
|
||||
QList<ABI::Windows::Networking::Sockets::IStreamSocket *> pendingConnections;
|
||||
|
Loading…
Reference in New Issue
Block a user