void Socket::CloseInternal(bool from_dtor)
{
- if (m_FD != INVALID_SOCKET) {
- closesocket(m_FD);
- m_FD = INVALID_SOCKET;
-
- /* 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);
- }
- }
+ if (m_FD == INVALID_SOCKET)
+ return;
+
+ 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)
"configrpc": { "replicate": "0", "configSource": "1" },
"demo": { "replicate": "0" }
},
- "rpcconnection": {
- "kekslistener": { "replicate": "0", "hostname": "::1", "port": "7777" }
- },
"rpclistener": {
"kekslistener": { "replicate": "0", "port": "7777" }
},
if (endpoint == neea.Endpoint)
return 0;
+ if (!neea.Endpoint->IsConnected())
+ return 0;
+
if (endpoint->GetIdentity() == neea.Endpoint->GetIdentity()) {
- Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting endpoint.");
+ Application::Log("Detected duplicate identity (" + endpoint->GetIdentity() + " - Disconnecting old endpoint.");
- endpoint->Stop();
- GetEndpointManager()->UnregisterEndpoint(endpoint);
+ neea.Endpoint->Stop();
+ GetEndpointManager()->UnregisterEndpoint(neea.Endpoint);
}
return 0;
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;
}
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;
void JsonRpcEndpoint::Stop(void)
{
- if (m_Client) {
+ if (m_Client)
m_Client->Close();
- m_Client = JsonRpcClient::Ptr();
- }
}
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);
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);
return true;
}
+bool VirtualEndpoint::IsConnected(void) const
+{
+ return true;
+}
+
void VirtualEndpoint::RegisterMethodHandler(string method, function<int (const NewRequestEventArgs&)> callback)
{
m_MethodHandlers[method] += callback;
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);