Revert "force the HTTPManager to listen on IPv4"

This reverts commit 220ad189a0.
This commit is contained in:
Stephen Birarda 2015-08-21 14:27:17 -07:00
parent 220ad189a0
commit 34b3fb1c0c
2 changed files with 26 additions and 8 deletions

View file

@ -29,14 +29,10 @@ HTTPManager::HTTPManager(quint16 port, const QString& documentRoot, HTTPRequestH
_requestHandler(requestHandler),
_port(port)
{
qCDebug(embeddedwebserver) << "Attempting to bind TCP socket on port " << QString::number(_port);
if (listen(QHostAddress::AnyIPv4, _port)) {
qCDebug(embeddedwebserver) << "TCP socket is listening on" << serverAddress() << "and port" << serverPort();
} else {
qCritical() << "Failed to open HTTP server socket:" << errorString() << " - forcing exit.";
QCoreApplication::exit(SOCKET_ERROR_EXIT_CODE);
}
bindSocket();
_isListeningTimer = new QTimer(this);
connect(_isListeningTimer, &QTimer::timeout, this, &HTTPManager::isTcpServerListening);
_isListeningTimer->start(SOCKET_CHECK_INTERVAL_IN_MS);
}
void HTTPManager::incomingConnection(qintptr socketDescriptor) {
@ -166,3 +162,18 @@ bool HTTPManager::requestHandledByRequestHandler(HTTPConnection* connection, con
return _requestHandler && _requestHandler->handleHTTPRequest(connection, url);
}
void HTTPManager::isTcpServerListening() {
if (!isListening()) {
qCWarning(embeddedwebserver) << "Socket on port " << QString::number(_port) << " is no longer listening";
bindSocket();
}
}
bool HTTPManager::bindSocket() {
qCDebug(embeddedwebserver) << "Attempting to bind TCP socket on port " << QString::number(_port);
if (!listen(QHostAddress::Any, _port)) {
qCritical() << "Failed to open HTTP server socket:" << errorString() << " can't continue";
QCoreApplication::exit(SOCKET_ERROR_EXIT_CODE);
}
return true;
}

View file

@ -37,6 +37,12 @@ public:
bool handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler = false);
private slots:
void isTcpServerListening();
private:
bool bindSocket();
protected:
/// Accepts all pending connections
virtual void incomingConnection(qintptr socketDescriptor);
@ -44,6 +50,7 @@ protected:
QString _documentRoot;
HTTPRequestHandler* _requestHandler;
QTimer* _isListeningTimer;
const quint16 _port;
};