Remove closed connections immediately

Previously it relied on a timer to drop dead connections but that proved to
be too slow when there is an incoming burst of connections.

Fixes #10487.
This commit is contained in:
Chocobo1 2019-04-15 19:52:49 +08:00
parent 19dfec1e0a
commit a35b6cc8dd
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
2 changed files with 11 additions and 3 deletions

View file

@ -108,15 +108,22 @@ void Server::incomingConnection(const qintptr socketDescriptor)
auto *c = new Connection(serverSocket, m_requestHandler, this);
m_connections.append(c);
connect(serverSocket, &QAbstractSocket::disconnected, this, [c, this]() { removeConnection(c); });
}
void Server::removeConnection(Connection *connection)
{
m_connections.removeOne(connection);
connection->deleteLater();
}
void Server::dropTimedOutConnection()
{
QMutableListIterator<Connection *> i(m_connections);
while (i.hasNext()) {
const auto *connection = i.next();
if (connection->isClosed() || connection->hasExpired(KEEP_ALIVE_DURATION)) {
delete connection;
Connection *connection = i.next();
if (connection->hasExpired(KEEP_ALIVE_DURATION)) {
connection->deleteLater();
i.remove();
}
}

View file

@ -56,6 +56,7 @@ namespace Http
private:
void incomingConnection(qintptr socketDescriptor);
void removeConnection(Connection *connection);
IRequestHandler *m_requestHandler;
QList<Connection *> m_connections; // for tracking persistent connections