|
|
@ -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(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|