QLocalSocket/Win: simplify flush()
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 <oswald.buddenhagen@gmx.de> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
3329212815
commit
f10491a9af
@ -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
|
||||
|
@ -53,7 +53,6 @@
|
||||
//
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qdeadlinetimer.h>
|
||||
#include <qmutex.h>
|
||||
#include <private/qringbuffer_p.h>
|
||||
|
||||
@ -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;
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user