Browse Source

Use QSet for tracking server connections

We don't need to maintain order between connections so QSet would be more suitable.
adaptive-webui-19844
Chocobo1 6 years ago
parent
commit
a2a669572c
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 6
      src/base/http/server.cpp
  2. 3
      src/base/http/server.h

6
src/base/http/server.cpp

@ -107,19 +107,19 @@ void Server::incomingConnection(const qintptr socketDescriptor) @@ -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<Connection *> i(m_connections);
QMutableSetIterator<Connection *> i(m_connections);
while (i.hasNext()) {
Connection *connection = i.next();
if (connection->hasExpired(KEEP_ALIVE_DURATION)) {

3
src/base/http/server.h

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
#ifndef HTTP_SERVER_H
#define HTTP_SERVER_H
#include <QSet>
#include <QSslCertificate>
#include <QSslKey>
#include <QTcpServer>
@ -59,7 +60,7 @@ namespace Http @@ -59,7 +60,7 @@ namespace Http
void removeConnection(Connection *connection);
IRequestHandler *m_requestHandler;
QList<Connection *> m_connections; // for tracking persistent connections
QSet<Connection *> m_connections; // for tracking persistent connections
bool m_https;
QList<QSslCertificate> m_certificates;

Loading…
Cancel
Save