summaryrefslogtreecommitdiffstats
path: root/src/corelib/io
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2021-06-23 18:26:10 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2021-07-06 17:52:58 +0300
commitb3fbfcd3738a0ff864439499390513b95ca671aa (patch)
treeac274d4652ea3415e9b0ef302c3c6bd146e15e4d /src/corelib/io
parent46d2ba1ea4d0e5f1a2ae1d1801e416e487ea45b4 (diff)
QLocalSocket: reimplement readLineData() function
The base implementation reads data using repeated calls to getChar(), which is quite slow. Change-Id: Ie46624df63791b2cdd3c8a28fe3327427d942505 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/corelib/io')
-rw-r--r--src/corelib/io/qwindowspipereader.cpp24
-rw-r--r--src/corelib/io/qwindowspipereader_p.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/src/corelib/io/qwindowspipereader.cpp b/src/corelib/io/qwindowspipereader.cpp
index 539902c233..c3ac51df94 100644
--- a/src/corelib/io/qwindowspipereader.cpp
+++ b/src/corelib/io/qwindowspipereader.cpp
@@ -209,6 +209,30 @@ qint64 QWindowsPipeReader::read(char *data, qint64 maxlen)
}
/*!
+ Reads a line from the internal buffer, but no more than \c{maxlen}
+ characters. A terminating '\0' byte is always appended to \c{data},
+ so \c{maxlen} must be larger than 1.
+ */
+qint64 QWindowsPipeReader::readLine(char *data, qint64 maxlen)
+{
+ QMutexLocker locker(&mutex);
+ qint64 readSoFar = 0;
+
+ if (actualReadBufferSize > 0) {
+ readSoFar = readBuffer.readLine(data, qMin(actualReadBufferSize + 1, maxlen));
+ actualReadBufferSize -= readSoFar;
+ }
+
+ if (!pipeBroken) {
+ startAsyncReadHelper(&locker);
+ if (readSoFar == 0)
+ return -2; // signal EWOULDBLOCK
+ }
+
+ return readSoFar;
+}
+
+/*!
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 77c90645c6..e2190d67d9 100644
--- a/src/corelib/io/qwindowspipereader_p.h
+++ b/src/corelib/io/qwindowspipereader_p.h
@@ -78,6 +78,7 @@ public:
bool isPipeClosed() const { return pipeBroken; }
qint64 bytesAvailable() const;
qint64 read(char *data, qint64 maxlen);
+ qint64 readLine(char *data, qint64 maxlen);
bool canReadLine() const;
DWORD checkPipeState();
bool checkForReadyRead() { return consumePendingAndEmit(false); }