Merge pull request #5632 from birarda/master

force the HTTPManager to listen on IPv4
This commit is contained in:
Seth Alves 2015-08-21 16:56:55 -07:00
commit 90483e7c97
2 changed files with 16 additions and 4 deletions

View file

@ -30,6 +30,7 @@ HTTPManager::HTTPManager(quint16 port, const QString& documentRoot, HTTPRequestH
_port(port)
{
bindSocket();
_isListeningTimer = new QTimer(this);
connect(_isListeningTimer, &QTimer::timeout, this, &HTTPManager::isTcpServerListening);
_isListeningTimer->start(SOCKET_CHECK_INTERVAL_IN_MS);
@ -171,9 +172,19 @@ void HTTPManager::isTcpServerListening() {
bool HTTPManager::bindSocket() {
qCDebug(embeddedwebserver) << "Attempting to bind TCP socket on port " << QString::number(_port);
if (!listen(QHostAddress::Any, _port)) {
if (listen(QHostAddress::AnyIPv4, _port)) {
qCDebug(embeddedwebserver) << "TCP socket is listening on" << serverAddress() << "and port" << serverPort();
return true;
} else {
qCritical() << "Failed to open HTTP server socket:" << errorString() << " can't continue";
QCoreApplication::exit(SOCKET_ERROR_EXIT_CODE);
QMetaObject::invokeMethod(this, "queuedExit", Qt::QueuedConnection);
return false;
}
return true;
}
}
void HTTPManager::queuedExit() {
QCoreApplication::exit(SOCKET_ERROR_EXIT_CODE);
}

View file

@ -39,6 +39,7 @@ public:
private slots:
void isTcpServerListening();
void queuedExit();
private:
bool bindSocket();