]> granicus.if.org Git - icinga2/commitdiff
Introduce JsonRpcConnection#SendMessageInternal()
authorAlexander A. Klimov <alexander.klimov@icinga.com>
Tue, 26 Feb 2019 09:17:10 +0000 (10:17 +0100)
committerAlexander A. Klimov <alexander.klimov@icinga.com>
Mon, 1 Apr 2019 11:31:16 +0000 (13:31 +0200)
lib/remote/jsonrpcconnection-heartbeat.cpp
lib/remote/jsonrpcconnection.cpp
lib/remote/jsonrpcconnection.hpp

index da6afe4b72967c97eeba35e320862da2b840fbae..f2e7f40453c88d3caa64219fcc54ed756a531d71 100644 (file)
@@ -36,15 +36,13 @@ void JsonRpcConnection::HandleAndWriteHeartbeats(boost::asio::yield_context yc)
                        break;
                }
 
-               m_OutgoingMessagesQueue.emplace_back(new Dictionary({
+               SendMessageInternal(new Dictionary({
                        { "jsonrpc", "2.0" },
                        { "method", "event::Heartbeat" },
                        { "params", new Dictionary({
                                { "timeout", 120 }
                        }) }
                }));
-
-               m_OutgoingMessagesQueued.Set();
        }
 }
 
index a0f37f950339f9466828b16193e7e9ffdb7f71af..16066a6aee3aced489481fafc9e5b28b9507a8a4 100644 (file)
@@ -160,10 +160,13 @@ ConnectionRole JsonRpcConnection::GetRole() const
 
 void JsonRpcConnection::SendMessage(const Dictionary::Ptr& message)
 {
-       m_IoStrand.post([this, message]() {
-               m_OutgoingMessagesQueue.emplace_back(message);
-               m_OutgoingMessagesQueued.Set();
-       });
+       m_IoStrand.post([this, message]() { SendMessageInternal(message); });
+}
+
+void JsonRpcConnection::SendMessageInternal(const Dictionary::Ptr& message)
+{
+       m_OutgoingMessagesQueue.emplace_back(message);
+       m_OutgoingMessagesQueued.Set();
 }
 
 void JsonRpcConnection::Disconnect()
@@ -277,8 +280,7 @@ void JsonRpcConnection::MessageHandler(const String& jsonString)
                resultMessage->Set("jsonrpc", "2.0");
                resultMessage->Set("id", message->Get("id"));
 
-               m_OutgoingMessagesQueue.emplace_back(resultMessage);
-               m_OutgoingMessagesQueued.Set();
+               SendMessageInternal(resultMessage);
        }
 }
 
index b0679d36818e65cf8f78c9b4d70163ee9628419c..8f48fc4cdff688315aa66fa0cd237b1e47db2cb6 100644 (file)
@@ -86,6 +86,8 @@ private:
        void MessageHandler(const String& jsonString);
 
        void CertificateRequestResponseHandler(const Dictionary::Ptr& message);
+
+       void SendMessageInternal(const Dictionary::Ptr& request);
 };
 
 }