diff --git a/src/base/http/server.cpp b/src/base/http/server.cpp index 778b94b39..2b27c3037 100644 --- a/src/base/http/server.cpp +++ b/src/base/http/server.cpp @@ -97,16 +97,23 @@ void Server::incomingConnection(qintptr socketDescriptor) #endif Connection *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.remove(connection); + connection->deleteLater(); } void Server::dropTimedOutConnection() { - QMutableListIterator i(m_connections); + QMutableSetIterator i(m_connections); while (i.hasNext()) { - 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(); } } diff --git a/src/base/http/server.h b/src/base/http/server.h index 91dc26dab..48846d533 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 #ifndef QT_NO_OPENSSL @@ -63,9 +64,10 @@ namespace Http private: void incomingConnection(qintptr socketDescriptor); + void removeConnection(Connection *connection); IRequestHandler *m_requestHandler; - QList m_connections; // for tracking persistent connections + QSet m_connections; // for tracking persistent connections #ifndef QT_NO_OPENSSL QList safeCipherList() const; diff --git a/src/base/utils/version.h b/src/base/utils/version.h index e82e3b6e9..b4bb4fee6 100644 --- a/src/base/utils/version.h +++ b/src/base/utils/version.h @@ -168,12 +168,12 @@ namespace Utils { if ((static_cast(versionParts.size()) > N) || (static_cast(versionParts.size()) < Mandatory)) - throw std::runtime_error ("Incorrect number of version components"); + throw std::runtime_error("Incorrect number of version components"); bool ok = false; ComponentsArray res {{}}; for (std::size_t i = 0; i < static_cast(versionParts.size()); ++i) { - res[i] = static_cast(versionParts[i].toInt(&ok)); + res[i] = static_cast(versionParts[static_cast(i)].toInt(&ok)); if (!ok) throw std::runtime_error("Can not parse version component"); }