Browse Source

Merge pull request #10492 from Chocobo1/server

Remove closed connections immediately
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
7db2d1b8cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      src/base/http/server.cpp
  2. 4
      src/base/http/server.h

17
src/base/http/server.cpp

@ -107,16 +107,23 @@ void Server::incomingConnection(const qintptr socketDescriptor)
} }
auto *c = new Connection(serverSocket, m_requestHandler, this); 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.remove(connection);
connection->deleteLater();
} }
void Server::dropTimedOutConnection() void Server::dropTimedOutConnection()
{ {
QMutableListIterator<Connection *> i(m_connections); QMutableSetIterator<Connection *> i(m_connections);
while (i.hasNext()) { while (i.hasNext()) {
const 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();
} }
} }

4
src/base/http/server.h

@ -31,6 +31,7 @@
#ifndef HTTP_SERVER_H #ifndef HTTP_SERVER_H
#define HTTP_SERVER_H #define HTTP_SERVER_H
#include <QSet>
#include <QSslCertificate> #include <QSslCertificate>
#include <QSslKey> #include <QSslKey>
#include <QTcpServer> #include <QTcpServer>
@ -56,9 +57,10 @@ 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 QSet<Connection *> m_connections; // for tracking persistent connections
bool m_https; bool m_https;
QList<QSslCertificate> m_certificates; QList<QSslCertificate> m_certificates;

Loading…
Cancel
Save