Add a `Server::isRunning` to know if the server is running or not.

This commit is contained in:
Matthieu Gautier 2022-10-07 16:20:24 +02:00
parent 7d83127d58
commit 1fcc2ad709
4 changed files with 18 additions and 0 deletions

View File

@ -117,6 +117,11 @@ namespace kiwix
*/
void stop();
/**
* Tell if the server is running or not.
*/
bool isRunning();
int getPort();
std::string getAddress();

View File

@ -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();

View File

@ -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,

View File

@ -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; }