From 4d94de8507e3dd528e68900fd758ef69a24d78ed Mon Sep 17 00:00:00 2001 From: Simon Fels Date: Tue, 28 Jun 2016 19:44:25 +0200 Subject: [PATCH] Fix small problems with RPC implementation --- src/anbox/bridge/connection_creator.cpp | 2 -- src/anbox/bridge/connection_creator.h | 3 ++- src/anbox/bridge/message_processor.cpp | 13 ++++++------- src/anbox/bridge/rpc_channel.cpp | 1 + 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/anbox/bridge/connection_creator.cpp b/src/anbox/bridge/connection_creator.cpp index 70f1c48..05efb10 100644 --- a/src/anbox/bridge/connection_creator.cpp +++ b/src/anbox/bridge/connection_creator.cpp @@ -47,8 +47,6 @@ void ConnectionCreator::create_connection_for( return; } - DEBUG(""); - auto const messenger = std::make_shared(socket); auto const processor = message_processor_factory_(messenger); diff --git a/src/anbox/bridge/connection_creator.h b/src/anbox/bridge/connection_creator.h index 892468b..711a12e 100644 --- a/src/anbox/bridge/connection_creator.h +++ b/src/anbox/bridge/connection_creator.h @@ -33,7 +33,8 @@ namespace anbox { namespace bridge { class ConnectionCreator : public network::ConnectionCreator { public: - typedef std::function(const std::shared_ptr&)> MessageProcessorFactory; + typedef std::function( + const std::shared_ptr&)> MessageProcessorFactory; ConnectionCreator( const std::shared_ptr &rt, const MessageProcessorFactory &factory); diff --git a/src/anbox/bridge/message_processor.cpp b/src/anbox/bridge/message_processor.cpp index 9872f9d..e596092 100644 --- a/src/anbox/bridge/message_processor.cpp +++ b/src/anbox/bridge/message_processor.cpp @@ -50,10 +50,12 @@ bool MessageProcessor::process_data(const std::vector &data) { for (const auto &byte : data) buffer_.push_back(byte); - unsigned char const high = buffer_[0]; - unsigned char const low = buffer_[1]; + buffer_.shrink_to_fit(); + + const auto high = buffer_[0]; + const auto low = buffer_[1]; size_t const message_size = (high << 8) + low; - unsigned char const message_type = buffer_[2]; + const auto message_type = buffer_[2]; // If we don't have yet all bytes for a new message return and wait // until we have all. @@ -74,10 +76,7 @@ bool MessageProcessor::process_data(const std::vector &data) { auto result = make_protobuf_object(); result->ParseFromArray(buffer_.data(), message_size); - buffer_.erase(buffer_.begin(), buffer_.end() + message_size); - - for (int i = 0; i != result->events_size(); ++i) - process_event_sequence(result->events(i)); + buffer_.erase(buffer_.begin(), buffer_.begin() + message_size); pending_calls_->complete_response(*result); } diff --git a/src/anbox/bridge/rpc_channel.cpp b/src/anbox/bridge/rpc_channel.cpp index e951d5f..7d5d2d5 100644 --- a/src/anbox/bridge/rpc_channel.cpp +++ b/src/anbox/bridge/rpc_channel.cpp @@ -57,6 +57,7 @@ protobuf::bridge::Invocation RpcChannel::invocation_for(std::string const& metho invoke.set_id(next_id()); invoke.set_method_name(method_name); invoke.set_parameters(buffer.data(), buffer.size()); + invoke.set_protocol_version(1); return invoke; }