mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-17 14:08:03 -06:00
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:
@@ -98,15 +98,22 @@ void Server::incomingConnection(qintptr socketDescriptor)
|
|||||||
|
|
||||||
Connection *c = new Connection(serverSocket, m_requestHandler, this);
|
Connection *c = new Connection(serverSocket, m_requestHandler, this);
|
||||||
m_connections.append(c);
|
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()
|
void Server::dropTimedOutConnection()
|
||||||
{
|
{
|
||||||
QMutableListIterator<Connection *> i(m_connections);
|
QMutableListIterator<Connection *> i(m_connections);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
auto connection = i.next();
|
Connection *connection = i.next();
|
||||||
if (connection->isClosed() || connection->hasExpired(KEEP_ALIVE_DURATION)) {
|
if (connection->hasExpired(KEEP_ALIVE_DURATION)) {
|
||||||
delete connection;
|
connection->deleteLater();
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ namespace Http
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void incomingConnection(qintptr socketDescriptor);
|
void incomingConnection(qintptr socketDescriptor);
|
||||||
|
void removeConnection(Connection *connection);
|
||||||
|
|
||||||
IRequestHandler *m_requestHandler;
|
IRequestHandler *m_requestHandler;
|
||||||
QList<Connection *> m_connections; // for tracking persistent connections
|
QList<Connection *> m_connections; // for tracking persistent connections
|
||||||
|
|||||||
Reference in New Issue
Block a user