diff --git a/base/socket.cpp b/base/socket.cpp index 2d0656ac9..7be38071a 100644 --- a/base/socket.cpp +++ b/base/socket.cpp @@ -50,21 +50,21 @@ void Socket::Close(void) void Socket::CloseInternal(bool from_dtor) { - if (m_FD != INVALID_SOCKET) { - closesocket(m_FD); - m_FD = INVALID_SOCKET; + if (m_FD == INVALID_SOCKET) + return; - /* nobody can possibly have a valid event subscription when the - destructor has been called */ - if (!from_dtor) { - EventArgs ea; - ea.Source = shared_from_this(); - OnClosed(ea); - } - } + closesocket(m_FD); + m_FD = INVALID_SOCKET; - if (!from_dtor) + /* nobody can possibly have a valid event subscription when the + destructor has been called */ + if (!from_dtor) { Stop(); + + EventArgs ea; + ea.Source = shared_from_this(); + OnClosed(ea); + } } void Socket::HandleSocketError(void) diff --git a/icinga-app/icinga.conf b/icinga-app/icinga.conf index 04916d95f..eeb6fc1c5 100644 --- a/icinga-app/icinga.conf +++ b/icinga-app/icinga.conf @@ -10,9 +10,6 @@ "configrpc": { "replicate": "0", "configSource": "1" }, "demo": { "replicate": "0" } }, - "rpcconnection": { - "kekslistener": { "replicate": "0", "hostname": "::1", "port": "7777" } - }, "rpclistener": { "kekslistener": { "replicate": "0", "port": "7777" } }, diff --git a/icinga/discoverycomponent.cpp b/icinga/discoverycomponent.cpp index a4682c2c7..e1ecc8b77 100644 --- a/icinga/discoverycomponent.cpp +++ b/icinga/discoverycomponent.cpp @@ -33,11 +33,14 @@ int DiscoveryComponent::CheckExistingEndpoint(Endpoint::Ptr endpoint, const NewE if (endpoint == neea.Endpoint) return 0; - if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) { - Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting endpoint."); + if (!neea.Endpoint->IsConnected()) + return 0; - endpoint->Stop(); - GetEndpointManager()->UnregisterEndpoint(endpoint); + if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) { + Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting old endpoint."); + + neea.Endpoint->Stop(); + GetEndpointManager()->UnregisterEndpoint(neea.Endpoint); } return 0; @@ -61,6 +64,7 @@ int DiscoveryComponent::WelcomeMessageHandler(const NewRequestEventArgs& neea) GetEndpointManager()->SendUnicastRequest(m_DiscoveryEndpoint, neea.Sender, request); /* TODO: send information about this client to all other clients */ + /* TODO: send stored events for this client */ return 0; } diff --git a/icinga/endpoint.h b/icinga/endpoint.h index 785a24bee..661dc5ddf 100644 --- a/icinga/endpoint.h +++ b/icinga/endpoint.h @@ -49,6 +49,7 @@ public: virtual bool IsAllowedMethodSource(string method) const = 0; virtual bool IsLocal(void) const = 0; + virtual bool IsConnected(void) const = 0; virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message) = 0; virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message) = 0; diff --git a/icinga/jsonrpcendpoint.cpp b/icinga/jsonrpcendpoint.cpp index 160305482..c0f57990c 100644 --- a/icinga/jsonrpcendpoint.cpp +++ b/icinga/jsonrpcendpoint.cpp @@ -201,8 +201,6 @@ int JsonRpcEndpoint::VerifyCertificateHandler(const VerifyCertificateEventArgs& void JsonRpcEndpoint::Stop(void) { - if (m_Client) { + if (m_Client) m_Client->Close(); - m_Client = JsonRpcClient::Ptr(); - } } diff --git a/icinga/jsonrpcendpoint.h b/icinga/jsonrpcendpoint.h index b04cb78f3..cd43446da 100644 --- a/icinga/jsonrpcendpoint.h +++ b/icinga/jsonrpcendpoint.h @@ -18,8 +18,6 @@ private: string m_PeerHostname; unsigned short m_PeerPort; - bool IsConnected(void) const; - int NewMessageHandler(const NewMessageEventArgs& nmea); int ClientClosedHandler(const EventArgs& ea); int ClientErrorHandler(const SocketErrorEventArgs& ea); @@ -47,6 +45,7 @@ public: virtual bool IsAllowedMethodSource(string method) const; virtual bool IsLocal(void) const; + virtual bool IsConnected(void) const; virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message); virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message); diff --git a/icinga/virtualendpoint.cpp b/icinga/virtualendpoint.cpp index fd43080d2..1d0b164da 100644 --- a/icinga/virtualendpoint.cpp +++ b/icinga/virtualendpoint.cpp @@ -14,6 +14,11 @@ bool VirtualEndpoint::IsLocal(void) const return true; } +bool VirtualEndpoint::IsConnected(void) const +{ + return true; +} + void VirtualEndpoint::RegisterMethodHandler(string method, function callback) { m_MethodHandlers[method] += callback; diff --git a/icinga/virtualendpoint.h b/icinga/virtualendpoint.h index 7c7cfbe71..815e9323e 100644 --- a/icinga/virtualendpoint.h +++ b/icinga/virtualendpoint.h @@ -35,6 +35,7 @@ public: virtual string GetAddress(void) const; virtual bool IsLocal(void) const; + virtual bool IsConnected(void) const; virtual void ProcessRequest(Endpoint::Ptr sender, const JsonRpcRequest& message); virtual void ProcessResponse(Endpoint::Ptr sender, const JsonRpcResponse& message);