From 79e95d2355acf4c781e171fbbc9467b61e14f21f Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Tue, 26 Feb 2019 10:17:10 +0100 Subject: [PATCH] Introduce JsonRpcConnection#SendMessageInternal() --- lib/remote/jsonrpcconnection-heartbeat.cpp | 4 +--- lib/remote/jsonrpcconnection.cpp | 14 ++++++++------ lib/remote/jsonrpcconnection.hpp | 2 ++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/remote/jsonrpcconnection-heartbeat.cpp b/lib/remote/jsonrpcconnection-heartbeat.cpp index da6afe4b7..f2e7f4045 100644 --- a/lib/remote/jsonrpcconnection-heartbeat.cpp +++ b/lib/remote/jsonrpcconnection-heartbeat.cpp @@ -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(); } } diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index a0f37f950..16066a6ae 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -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); } } diff --git a/lib/remote/jsonrpcconnection.hpp b/lib/remote/jsonrpcconnection.hpp index b0679d368..8f48fc4cd 100644 --- a/lib/remote/jsonrpcconnection.hpp +++ b/lib/remote/jsonrpcconnection.hpp @@ -86,6 +86,8 @@ private: void MessageHandler(const String& jsonString); void CertificateRequestResponseHandler(const Dictionary::Ptr& message); + + void SendMessageInternal(const Dictionary::Ptr& request); }; } -- 2.50.0