From f10491a9afe7d6e11456b2c4b2c5f6eaf1594737 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Mon, 26 Apr 2021 19:50:14 +0300 Subject: [PATCH] QLocalSocket/Win: simplify flush() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replacing a call to waitForWrite(0) with checkForWrite() changes nothing in logic, but saves one system call. As a result, unused functions in the QWindowsPipeWriter class have been removed. Change-Id: I34ec6310d9659f59a720056b9be54e31f2193116 Reviewed-by: Oswald Buddenhagen Reviewed-by: MÃ¥rten Nordheim --- src/corelib/io/qwindowspipewriter.cpp | 43 ------------------------- src/corelib/io/qwindowspipewriter_p.h | 4 --- src/network/socket/qlocalsocket_win.cpp | 6 ++-- 3 files changed, 2 insertions(+), 51 deletions(-) diff --git a/src/corelib/io/qwindowspipewriter.cpp b/src/corelib/io/qwindowspipewriter.cpp index 6a5e43db0d..2db3cb4060 100644 --- a/src/corelib/io/qwindowspipewriter.cpp +++ b/src/corelib/io/qwindowspipewriter.cpp @@ -114,16 +114,6 @@ void QWindowsPipeWriter::stop() WaitForThreadpoolWaitCallbacks(waitObject, TRUE); } -/*! - Returns \c true if async operation is in progress or a bytesWritten - signal is pending. - */ -bool QWindowsPipeWriter::isWriteOperationActive() const -{ - QMutexLocker locker(&mutex); - return writeSequenceStarted || bytesWrittenPending; -} - /*! Returns the number of bytes that are waiting to be written. */ @@ -322,37 +312,4 @@ bool QWindowsPipeWriter::consumePendingAndEmit(bool allowWinActPosting) return true; } -bool QWindowsPipeWriter::waitForNotification(const QDeadlineTimer &deadline) -{ - do { - DWORD waitRet = WaitForSingleObjectEx(syncHandle, deadline.remainingTime(), TRUE); - if (waitRet == WAIT_OBJECT_0) - return true; - - if (waitRet != WAIT_IO_COMPLETION) - return false; - - // Some I/O completion routine was called. Wait some more. - } while (!deadline.hasExpired()); - - return false; -} - -/*! - Waits for the completion of the asynchronous write operation. - Returns \c true, if we've emitted the bytesWritten signal. - */ -bool QWindowsPipeWriter::waitForWrite(int msecs) -{ - QDeadlineTimer timer(msecs); - - // Make sure that 'syncHandle' was triggered by the thread pool callback. - while (isWriteOperationActive() && waitForNotification(timer)) { - if (consumePendingAndEmit(false)) - return true; - } - - return false; -} - QT_END_NAMESPACE diff --git a/src/corelib/io/qwindowspipewriter_p.h b/src/corelib/io/qwindowspipewriter_p.h index e20f1ec90a..8a3b3068e5 100644 --- a/src/corelib/io/qwindowspipewriter_p.h +++ b/src/corelib/io/qwindowspipewriter_p.h @@ -53,7 +53,6 @@ // #include -#include #include #include @@ -72,9 +71,7 @@ public: bool write(const QByteArray &ba); bool write(const char *data, qint64 size); void stop(); - bool waitForWrite(int msecs); bool checkForWrite() { return consumePendingAndEmit(false); } - bool isWriteOperationActive() const; qint64 bytesToWrite() const; HANDLE syncEvent() const { return syncHandle; } @@ -92,7 +89,6 @@ private: static void CALLBACK waitCallback(PTP_CALLBACK_INSTANCE instance, PVOID context, PTP_WAIT wait, TP_WAIT_RESULT waitResult); bool writeCompleted(DWORD errorCode, DWORD numberOfBytesWritten); - bool waitForNotification(const QDeadlineTimer &deadline); bool consumePendingAndEmit(bool allowWinActPosting); HANDLE handle; diff --git a/src/network/socket/qlocalsocket_win.cpp b/src/network/socket/qlocalsocket_win.cpp index 912ebf412c..aa5c12b5b8 100644 --- a/src/network/socket/qlocalsocket_win.cpp +++ b/src/network/socket/qlocalsocket_win.cpp @@ -377,10 +377,8 @@ void QLocalSocket::close() bool QLocalSocket::flush() { Q_D(QLocalSocket); - bool written = false; - while (d->pipeWriter && d->pipeWriter->waitForWrite(0)) - written = true; - return written; + + return d->pipeWriter && d->pipeWriter->checkForWrite(); } void QLocalSocket::disconnectFromServer()