Merge pull request #10496 from Chocobo1/backport

Backport to v4_1_x
This commit is contained in:
Mike Tzou 2019-04-17 13:13:25 +08:00 committed by GitHub
commit 4253515736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 8 deletions

View file

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

View file

@ -31,6 +31,7 @@
#ifndef HTTP_SERVER_H #ifndef HTTP_SERVER_H
#define HTTP_SERVER_H #define HTTP_SERVER_H
#include <QSet>
#include <QTcpServer> #include <QTcpServer>
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
@ -63,9 +64,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
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
QList<QSslCipher> safeCipherList() const; QList<QSslCipher> safeCipherList() const;

View file

@ -173,7 +173,7 @@ namespace Utils
bool ok = false; bool ok = false;
ComponentsArray res {{}}; ComponentsArray res {{}};
for (std::size_t i = 0; i < static_cast<std::size_t>(versionParts.size()); ++i) { for (std::size_t i = 0; i < static_cast<std::size_t>(versionParts.size()); ++i) {
res[i] = static_cast<T>(versionParts[i].toInt(&ok)); res[i] = static_cast<T>(versionParts[static_cast<typename StringsList::size_type>(i)].toInt(&ok));
if (!ok) if (!ok)
throw std::runtime_error("Can not parse version component"); throw std::runtime_error("Can not parse version component");
} }