summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2021-07-02 17:31:26 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2021-07-08 16:14:11 +0300
commit1a57a4974be9dbdeedef6f5c6eb4332eecf6f0c9 (patch)
tree383496919e92f6fe57e87d157a6d34bc5b29641c /src
parent82499f81478032911d8f788aa28e8d780b31c973 (diff)
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 <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qwindowspipereader.cpp19
-rw-r--r--src/corelib/io/qwindowspipereader_p.h1
-rw-r--r--src/network/socket/qlocalsocket_win.cpp7
3 files changed, 26 insertions, 1 deletions
diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp
index c3ac51df949..5415ad7830e 100644
--- a/src/corelib/io/qwindowspipereader.cpp
+++ b/src/corelib/io/qwindowspipereader.cpp
@@ -233,6 +233,25 @@ qint64 QWindowsPipeReader::readLine(char *data, qint64 maxlen)
}
/*!
+ 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.
*/
bool QWindowsPipeReader::canReadLine() const
diff --git a/src/corelib/io/qwindowspipereader_p.h b/src/corelib/io/qwindowspipereader_p.h
index e2190d67d92..5eb62cb393d 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); }
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp
index 89901533af1..e430f642db9 100644
--- a/src/network/socket/qlocalsocket_win.cpp
+++ b/src/network/socket/qlocalsocket_win.cpp
@@ -277,7 +277,12 @@ qint64 QLocalSocket::readLineData(char *data, qint64 maxSize)
qint64 QLocalSocket::skipData(qint64 maxSize)
{
- return QIODevice::skipData(maxSize);
+ Q_D(QLocalSocket);
+
+ if (!maxSize)
+ return 0;
+
+ return transformPipeReaderResult(d->pipeReader->skip(maxSize));
}
qint64 QLocalSocket::writeData(const char *data, qint64 len)