From 1fcc2ad709ec7f0120d5bdad242bfcf20d7a6578 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Fri, 7 Oct 2022 16:20:24 +0200 Subject: [PATCH] Add a `Server::isRunning` to know if the server is running or not. --- include/server.h | 5 +++++ src/server.cpp | 7 +++++++ src/server/internalServer.cpp | 5 +++++ src/server/internalServer.h | 1 + 4 files changed, 18 insertions(+) diff --git a/include/server.h b/include/server.h index 5d3677796..0ce613f21 100644 --- a/include/server.h +++ b/include/server.h @@ -117,6 +117,11 @@ namespace kiwix */ void stop(); + /** + * Tell if the server is running or not. + */ + bool isRunning(); + int getPort(); std::string getAddress(); diff --git a/src/server.cpp b/src/server.cpp index 425e88dba..4388f471e 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -61,6 +61,13 @@ void Server::stop() { } } +bool Server::isRunning() { + if (!mp_server) { + return false; + } + return mp_server->isRunning(); +} + int Server::getPort() { return mp_server->getPort(); diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 7eece05b5..c4d2ae02d 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -415,8 +415,13 @@ bool InternalServer::start() { void InternalServer::stop() { MHD_stop_daemon(mp_daemon); + mp_daemon = nullptr; } +bool InternalServer::isRunning() const +{ + return mp_daemon != nullptr; +} static MHD_Result staticHandlerCallback(void* cls, struct MHD_Connection* connection, const char* url, diff --git a/src/server/internalServer.h b/src/server/internalServer.h index d44434e0a..efd25a928 100644 --- a/src/server/internalServer.h +++ b/src/server/internalServer.h @@ -104,6 +104,7 @@ class InternalServer : Server::Configuration { void** cont_cls); bool start(); void stop(); + bool isRunning() const; std::string getAddress() { return m_addr; } int getPort() { return m_port; }