diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2021-04-12 16:31:51 +0300 |
---|---|---|
committer | Oswald Buddenhagen <oswald.buddenhagen@gmx.de> | 2021-04-15 19:00:42 +0000 |
commit | 063cdb9870ab8a9b0f1a3741a001c06289f02af4 (patch) | |
tree | 3dcba5254f8ae4d2f250ffadaec0f93f865048e7 /src/network/socket/qlocalsocket_win.cpp | |
parent | 92d351089bf7e285c9800342ff72205c04984f6c (diff) |
QWindowsPipe{Reader|Writer}: restructure signals
For QProcess, there is no point in suppressing recursive
QWPR::readyRead() emission, as the former manages this logic itself. On
top of that, the non-recursive nature of QWPR::readyRead() indirectly
disallowed reading from the channels inside
QProcess::waitForReadyRead(), if that is called from a slot connected
to QProcess::readyRead().
QWPW had two signals, one allowing recursion and one not.
This commit allows recursion of QWPR::readyRead() and
QWPW::bytesWritten(), and moves recursion suppression to the higher-
level classes. This makes the code more uniform and efficient, at the
cost of a few duplicated lines.
Change-Id: Ib20017fff4d92403d0bf2335f1622de4aa1ddcef
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Diffstat (limited to 'src/network/socket/qlocalsocket_win.cpp')
-rw-r--r-- | src/network/socket/qlocalsocket_win.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index 677b431265..66eed86501 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qlocalsocket_p.h" +#include <qscopedvaluerollback.h> QT_BEGIN_NAMESPACE @@ -45,7 +46,8 @@ void QLocalSocketPrivate::init() { Q_Q(QLocalSocket); pipeReader = new QWindowsPipeReader(q); - q->connect(pipeReader, SIGNAL(readyRead()), SIGNAL(readyRead())); + QObjectPrivate::connect(pipeReader, &QWindowsPipeReader::readyRead, + this, &QLocalSocketPrivate::_q_canRead); q->connect(pipeReader, SIGNAL(pipeClosed()), SLOT(_q_pipeClosed()), Qt::QueuedConnection); q->connect(pipeReader, SIGNAL(winError(ulong,QString)), SLOT(_q_winError(ulong,QString))); } @@ -99,7 +101,9 @@ QLocalSocketPrivate::QLocalSocketPrivate() : QIODevicePrivate(), pipeWriter(0), pipeReader(0), error(QLocalSocket::UnknownSocketError), - state(QLocalSocket::UnconnectedState) + state(QLocalSocket::UnconnectedState), + emittedReadyRead(false), + emittedBytesWritten(false) { writeBufferChunkSize = QIODEVICE_BUFFERSIZE; } @@ -223,10 +227,8 @@ qint64 QLocalSocket::writeData(const char *data, qint64 len) d->write(data, len); if (!d->pipeWriter) { d->pipeWriter = new QWindowsPipeWriter(d->handle, this); - connect(d->pipeWriter, &QWindowsPipeWriter::bytesWritten, - this, &QLocalSocket::bytesWritten); - QObjectPrivate::connect(d->pipeWriter, &QWindowsPipeWriter::canWrite, - d, &QLocalSocketPrivate::_q_canWrite); + QObjectPrivate::connect(d->pipeWriter, &QWindowsPipeWriter::bytesWritten, + d, &QLocalSocketPrivate::_q_bytesWritten); } d->_q_canWrite(); return len; @@ -242,6 +244,15 @@ void QLocalSocket::abort() close(); } +void QLocalSocketPrivate::_q_canRead() +{ + Q_Q(QLocalSocket); + if (!emittedReadyRead) { + QScopedValueRollback<bool> guard(emittedReadyRead, true); + emit q->readyRead(); + } +} + void QLocalSocketPrivate::_q_pipeClosed() { Q_Q(QLocalSocket); @@ -359,6 +370,16 @@ bool QLocalSocket::setSocketDescriptor(qintptr socketDescriptor, return true; } +void QLocalSocketPrivate::_q_bytesWritten(qint64 bytes) +{ + Q_Q(QLocalSocket); + if (!emittedBytesWritten) { + QScopedValueRollback<bool> guard(emittedBytesWritten, true); + emit q->bytesWritten(bytes); + } + _q_canWrite(); +} + void QLocalSocketPrivate::_q_canWrite() { Q_Q(QLocalSocket); |