mirror of
https://github.com/lubosz/overte.git
synced 2025-04-09 09:44:33 +02:00
leave the listen check but queue Application quit
This commit is contained in:
parent
34b3fb1c0c
commit
3e4a05a57b
1 changed files with 12 additions and 5 deletions
|
@ -20,7 +20,6 @@
|
|||
#include "EmbeddedWebserverLogging.h"
|
||||
#include "HTTPManager.h"
|
||||
|
||||
const int SOCKET_ERROR_EXIT_CODE = 2;
|
||||
const int SOCKET_CHECK_INTERVAL_IN_MS = 30000;
|
||||
|
||||
HTTPManager::HTTPManager(quint16 port, const QString& documentRoot, HTTPRequestHandler* requestHandler, QObject* parent) :
|
||||
|
@ -30,6 +29,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 +171,16 @@ 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(QCoreApplication::instance(), "quit", Qt::QueuedConnection);
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue