Skip to content

Commit

Permalink
Add a Server::isRunning to know if the server is running or not.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Oct 7, 2022
1 parent 064a604 commit 2130b1a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ namespace kiwix
*/
void stop();

/**
* Tell if the server is running or not.
*/
bool isRunning();

int getPort();
std::string getAddress();

Expand Down
7 changes: 7 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/server/internalServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/server/internalServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class InternalServer {
void** cont_cls);
bool start();
void stop();
bool isRunning() const;
std::string getAddress() { return m_addr; }
int getPort() { return m_configuration.m_port; }

Expand Down

0 comments on commit 2130b1a

Please sign in to comment.