diff --git a/lib/livestatus/livestatuslistener.cpp b/lib/livestatus/livestatuslistener.cpp index 634973352..3f43d63e9 100644 --- a/lib/livestatus/livestatuslistener.cpp +++ b/lib/livestatus/livestatuslistener.cpp @@ -70,6 +70,7 @@ void LivestatusListener::Start(void) if (GetSocketType() == "tcp") { TcpSocket::Ptr socket = new TcpSocket(); + try { socket->Bind(GetBindHost(), GetBindPort(), AF_UNSPEC); } catch (std::exception&) { @@ -78,6 +79,8 @@ void LivestatusListener::Start(void) return; } + m_Listener = socket; + boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket)); thread.detach(); Log(LogInformation, "LivestatusListener") @@ -86,6 +89,7 @@ void LivestatusListener::Start(void) else if (GetSocketType() == "unix") { #ifndef _WIN32 UnixSocket::Ptr socket = new UnixSocket(); + try { socket->Bind(GetSocketPath()); } catch (std::exception&) { @@ -103,6 +107,8 @@ void LivestatusListener::Start(void) return; } + m_Listener = socket; + boost::thread thread(boost::bind(&LivestatusListener::ServerThreadProc, this, socket)); thread.detach(); Log(LogInformation, "LivestatusListener") @@ -115,6 +121,13 @@ void LivestatusListener::Start(void) } } +void LivestatusListener::Stop(void) +{ + DynamicObject::Stop(); + + m_Listener->Close(); +} + int LivestatusListener::GetClientsConnected(void) { boost::mutex::scoped_lock lock(l_ComponentMutex); diff --git a/lib/livestatus/livestatuslistener.hpp b/lib/livestatus/livestatuslistener.hpp index ba298d4cd..3585a8dd1 100644 --- a/lib/livestatus/livestatuslistener.hpp +++ b/lib/livestatus/livestatuslistener.hpp @@ -48,10 +48,13 @@ public: protected: virtual void Start(void); + virtual void Stop(void); private: void ServerThreadProc(const Socket::Ptr& server); void ClientHandler(const Socket::Ptr& client); + + Socket::Ptr m_Listener; }; }