From aedd99760407f86b8595c857616611028fe86ca7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 18 Dec 2021 12:28:30 +0800 Subject: [PATCH] Don't expire connection when there are data in buffer For writing, this ensures expire handler won't be executed in a small time window, that is after `m_socket->write()` and before `QIODevice::bytesWritten()` signal. For reading, this let the socket to have the chance to process the received data instead of dropping it. PR #15849. --- src/base/http/connection.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/base/http/connection.cpp b/src/base/http/connection.cpp index f8bb1cf2b..fc6ac78b2 100644 --- a/src/base/http/connection.cpp +++ b/src/base/http/connection.cpp @@ -134,7 +134,9 @@ void Connection::sendResponse(const Response &response) const bool Connection::hasExpired(const qint64 timeout) const { - return m_idleTimer.hasExpired(timeout); + return (m_socket->bytesAvailable() == 0) + && (m_socket->bytesToWrite() == 0) + && m_idleTimer.hasExpired(timeout); } bool Connection::isClosed() const