From 1a57a4974be9dbdeedef6f5c6eb4332eecf6f0c9 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Fri, 2 Jul 2021 17:31:26 +0300 Subject: QLocalSocket/Win: reimplement skipData() function The base implementation discards the data by reading into a dummy buffer, which is slower than necessary. Change-Id: Iabf0c4a25746af6cac5b61d7bda66d89501c808c Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qwindowspipereader.cpp | 19 +++++++++++++++++++ src/corelib/io/qwindowspipereader_p.h | 1 + 2 files changed, 20 insertions(+) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp index c3ac51df94..5415ad7830 100644 --- a/src/corelib/io/qwindowspipereader.cpp +++ b/src/corelib/io/qwindowspipereader.cpp @@ -232,6 +232,25 @@ qint64 QWindowsPipeReader::readLine(char *data, qint64 maxlen) return readSoFar; } +/*! + Skips up to \c{maxlen} bytes from the internal read buffer. + */ +qint64 QWindowsPipeReader::skip(qint64 maxlen) +{ + QMutexLocker locker(&mutex); + + const qint64 skippedSoFar = readBuffer.skip(qMin(actualReadBufferSize, maxlen)); + actualReadBufferSize -= skippedSoFar; + + if (!pipeBroken) { + startAsyncReadHelper(&locker); + if (skippedSoFar == 0) + return -2; // signal EWOULDBLOCK + } + + return skippedSoFar; +} + /*! Returns \c true if a complete line of data can be read from the buffer. */ diff --git a/src/corelib/io/qwindowspipereader_p.h b/src/corelib/io/qwindowspipereader_p.h index e2190d67d9..5eb62cb393 100644 --- a/src/corelib/io/qwindowspipereader_p.h +++ b/src/corelib/io/qwindowspipereader_p.h @@ -79,6 +79,7 @@ public: qint64 bytesAvailable() const; qint64 read(char *data, qint64 maxlen); qint64 readLine(char *data, qint64 maxlen); + qint64 skip(qint64 maxlen); bool canReadLine() const; DWORD checkPipeState(); bool checkForReadyRead() { return consumePendingAndEmit(false); } -- cgit v1.2.3