Explicitely manage HTTPManager lifetime

This commit is contained in:
Clement 2018-05-18 15:01:19 -07:00
parent cc2d8bebef
commit e096ff91f6
11 changed files with 11 additions and 18 deletions

View file

@ -233,7 +233,6 @@ OctreeServer::OctreeServer(ReceivedMessage& message) :
_argc(0), _argc(0),
_argv(NULL), _argv(NULL),
_parsedArgV(NULL), _parsedArgV(NULL),
_httpManager(NULL),
_statusPort(0), _statusPort(0),
_packetsPerClientPerInterval(10), _packetsPerClientPerInterval(10),
_packetsTotalPerInterval(DEFAULT_PACKETS_PER_INTERVAL), _packetsTotalPerInterval(DEFAULT_PACKETS_PER_INTERVAL),
@ -285,7 +284,7 @@ void OctreeServer::initHTTPManager(int port) {
QString documentRoot = QString("%1/web").arg(PathUtils::getAppDataPath()); QString documentRoot = QString("%1/web").arg(PathUtils::getAppDataPath());
// setup an httpManager with us as the request handler and the parent // setup an httpManager with us as the request handler and the parent
_httpManager = new HTTPManager(QHostAddress::AnyIPv4, port, documentRoot, this, this); _httpManager.reset(new HTTPManager(QHostAddress::AnyIPv4, port, documentRoot, this));
} }
bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) { bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) {

View file

@ -183,7 +183,7 @@ protected:
bool _isShuttingDown = false; bool _isShuttingDown = false;
HTTPManager* _httpManager; std::unique_ptr<HTTPManager> _httpManager;
int _statusPort; int _statusPort;
QString _statusHost; QString _statusHost;

View file

@ -149,7 +149,6 @@ DomainServer::DomainServer(int argc, char* argv[]) :
QCoreApplication(argc, argv), QCoreApplication(argc, argv),
_gatekeeper(this), _gatekeeper(this),
_httpManager(QHostAddress::AnyIPv4, DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this), _httpManager(QHostAddress::AnyIPv4, DOMAIN_SERVER_HTTP_PORT, QString("%1/resources/web/").arg(QCoreApplication::applicationDirPath()), this),
_httpsManager(NULL),
_allAssignments(), _allAssignments(),
_unfulfilledAssignments(), _unfulfilledAssignments(),
_isUsingDTLS(false), _isUsingDTLS(false),
@ -439,7 +438,7 @@ bool DomainServer::optionallyReadX509KeyAndCertificate() {
QSslCertificate sslCertificate(&certFile); QSslCertificate sslCertificate(&certFile);
QSslKey privateKey(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, keyPassphraseString.toUtf8()); QSslKey privateKey(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey, keyPassphraseString.toUtf8());
_httpsManager = new HTTPSManager(QHostAddress::AnyIPv4, DOMAIN_SERVER_HTTPS_PORT, sslCertificate, privateKey, QString(), this, this); _httpsManager.reset(new HTTPSManager(QHostAddress::AnyIPv4, DOMAIN_SERVER_HTTPS_PORT, sslCertificate, privateKey, QString(), this));
qDebug() << "TCP server listening for HTTPS connections on" << DOMAIN_SERVER_HTTPS_PORT; qDebug() << "TCP server listening for HTTPS connections on" << DOMAIN_SERVER_HTTPS_PORT;

View file

@ -220,7 +220,7 @@ private:
DomainGatekeeper _gatekeeper; DomainGatekeeper _gatekeeper;
HTTPManager _httpManager; HTTPManager _httpManager;
HTTPSManager* _httpsManager; std::unique_ptr<HTTPSManager> _httpsManager;
QHash<QUuid, SharedAssignmentPointer> _allAssignments; QHash<QUuid, SharedAssignmentPointer> _allAssignments;
QQueue<SharedAssignmentPointer> _unfulfilledAssignments; QQueue<SharedAssignmentPointer> _unfulfilledAssignments;

View file

@ -33,7 +33,6 @@ HTTPConnection::HTTPConnection (QTcpSocket* socket, HTTPManager* parentManager)
QObject(parentManager), QObject(parentManager),
_parentManager(parentManager), _parentManager(parentManager),
_socket(socket), _socket(socket),
_stream(socket),
_address(socket->peerAddress()) _address(socket->peerAddress())
{ {
// take over ownership of the socket // take over ownership of the socket

View file

@ -113,9 +113,6 @@ protected:
/// The underlying socket. /// The underlying socket.
QTcpSocket* _socket; QTcpSocket* _socket;
/// The data stream for writing to the socket.
QDataStream _stream;
/// The stored address. /// The stored address.
QHostAddress _address; QHostAddress _address;

View file

@ -24,8 +24,7 @@
const int SOCKET_ERROR_EXIT_CODE = 2; const int SOCKET_ERROR_EXIT_CODE = 2;
const int SOCKET_CHECK_INTERVAL_IN_MS = 30000; const int SOCKET_CHECK_INTERVAL_IN_MS = 30000;
HTTPManager::HTTPManager(const QHostAddress& listenAddress, quint16 port, const QString& documentRoot, HTTPRequestHandler* requestHandler, QObject* parent) : HTTPManager::HTTPManager(const QHostAddress& listenAddress, quint16 port, const QString& documentRoot, HTTPRequestHandler* requestHandler) :
QTcpServer(parent),
_listenAddress(listenAddress), _listenAddress(listenAddress),
_documentRoot(documentRoot), _documentRoot(documentRoot),
_requestHandler(requestHandler), _requestHandler(requestHandler),

View file

@ -33,7 +33,7 @@ class HTTPManager : public QTcpServer, public HTTPRequestHandler {
Q_OBJECT Q_OBJECT
public: public:
/// Initializes the manager. /// Initializes the manager.
HTTPManager(const QHostAddress& listenAddress, quint16 port, const QString& documentRoot, HTTPRequestHandler* requestHandler = NULL, QObject* parent = 0); HTTPManager(const QHostAddress& listenAddress, quint16 port, const QString& documentRoot, HTTPRequestHandler* requestHandler = NULL);
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false) override; bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false) override;

View file

@ -16,8 +16,8 @@
#include "HTTPSConnection.h" #include "HTTPSConnection.h"
HTTPSManager::HTTPSManager(QHostAddress listenAddress, quint16 port, const QSslCertificate& certificate, const QSslKey& privateKey, HTTPSManager::HTTPSManager(QHostAddress listenAddress, quint16 port, const QSslCertificate& certificate, const QSslKey& privateKey,
const QString& documentRoot, HTTPSRequestHandler* requestHandler, QObject* parent) : const QString& documentRoot, HTTPSRequestHandler* requestHandler) :
HTTPManager(listenAddress, port, documentRoot, requestHandler, parent), HTTPManager(listenAddress, port, documentRoot, requestHandler),
_certificate(certificate), _certificate(certificate),
_privateKey(privateKey), _privateKey(privateKey),
_sslRequestHandler(requestHandler) _sslRequestHandler(requestHandler)

View file

@ -31,7 +31,7 @@ public:
const QSslCertificate& certificate, const QSslCertificate& certificate,
const QSslKey& privateKey, const QSslKey& privateKey,
const QString& documentRoot, const QString& documentRoot,
HTTPSRequestHandler* requestHandler = NULL, QObject* parent = 0); HTTPSRequestHandler* requestHandler = NULL);
void setCertificate(const QSslCertificate& certificate) { _certificate = certificate; } void setCertificate(const QSslCertificate& certificate) { _certificate = certificate; }
void setPrivateKey(const QSslKey& privateKey) { _privateKey = privateKey; } void setPrivateKey(const QSslKey& privateKey) { _privateKey = privateKey; }