mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 13:53:37 -07:00
commit
4253515736
3 changed files with 17 additions and 8 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -168,12 +168,12 @@ namespace Utils
|
||||||
{
|
{
|
||||||
if ((static_cast<std::size_t>(versionParts.size()) > N)
|
if ((static_cast<std::size_t>(versionParts.size()) > N)
|
||||||
|| (static_cast<std::size_t>(versionParts.size()) < Mandatory))
|
|| (static_cast<std::size_t>(versionParts.size()) < Mandatory))
|
||||||
throw std::runtime_error ("Incorrect number of version components");
|
throw std::runtime_error("Incorrect number of version components");
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue