From a2a669572caf7e03594aaed9939dc0bc0e31e63e Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 15 Apr 2019 21:22:11 +0800 Subject: [PATCH] Use QSet for tracking server connections We don't need to maintain order between connections so QSet would be more suitable. --- src/base/http/server.cpp | 6 +++--- src/base/http/server.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/base/http/server.cpp b/src/base/http/server.cpp index 8dcf3174c..8fb01e655 100644 --- a/src/base/http/server.cpp +++ b/src/base/http/server.cpp @@ -107,19 +107,19 @@ void Server::incomingConnection(const qintptr socketDescriptor) } auto *c = new Connection(serverSocket, m_requestHandler, this); - m_connections.append(c); + m_connections.insert(c); connect(serverSocket, &QAbstractSocket::disconnected, this, [c, this]() { removeConnection(c); }); } void Server::removeConnection(Connection *connection) { - m_connections.removeOne(connection); + m_connections.remove(connection); connection->deleteLater(); } void Server::dropTimedOutConnection() { - QMutableListIterator i(m_connections); + QMutableSetIterator i(m_connections); while (i.hasNext()) { Connection *connection = i.next(); if (connection->hasExpired(KEEP_ALIVE_DURATION)) { diff --git a/src/base/http/server.h b/src/base/http/server.h index 415e905ac..e0433f96c 100644 --- a/src/base/http/server.h +++ b/src/base/http/server.h @@ -31,6 +31,7 @@ #ifndef HTTP_SERVER_H #define HTTP_SERVER_H +#include #include #include #include @@ -59,7 +60,7 @@ namespace Http void removeConnection(Connection *connection); IRequestHandler *m_requestHandler; - QList m_connections; // for tracking persistent connections + QSet m_connections; // for tracking persistent connections bool m_https; QList m_certificates;