提交 183c02d2 编写于 作者: S Simon Fels

Make adb message processor more robust in shutdown scenarios

上级 14d77e9c
......@@ -16,10 +16,10 @@
*/
#include "anbox/qemu/adb_message_processor.h"
#include "anbox/logger.h"
#include "anbox/network/delegate_connection_creator.h"
#include "anbox/network/delegate_message_processor.h"
#include "anbox/network/tcp_socket_messenger.h"
#include "anbox/utils.h"
#include <fstream>
#include <functional>
......@@ -54,7 +54,11 @@ AdbMessageProcessor::AdbMessageProcessor(
AdbMessageProcessor::~AdbMessageProcessor() {
state_ = closed_by_host;
host_notify_timer_.cancel();
host_connector_.reset();
// Unlock our lock to bring down any waiting instance
active_instance.unlock();
}
......@@ -68,6 +72,7 @@ void AdbMessageProcessor::advance_state() {
active_instance.lock();
if (state_ == closed_by_host) {
host_notify_timer_.cancel();
host_connector_.reset();
return;
}
......@@ -104,6 +109,9 @@ void AdbMessageProcessor::advance_state() {
}
void AdbMessageProcessor::wait_for_host_connection() {
if (state_ == closed_by_host || state_ == closed_by_container)
return;
if (!host_connector_) {
host_connector_ = std::make_shared<network::TcpSocketConnector>(
boost::asio::ip::address_v4::from_string(loopback_address),
......@@ -121,11 +129,11 @@ void AdbMessageProcessor::wait_for_host_connection() {
auto message = utils::string_format("host:emulator:%d", default_host_listen_port);
auto handshake = utils::string_format("%04x%s", message.size(), message.c_str());
messenger->send(handshake.data(), handshake.size());
} catch (std::exception &) {
} catch (...) {
// Try again later when the host adb service is maybe available
host_notify_timer_.cancel();
host_notify_timer_.expires_from_now(default_adb_wait_time);
host_notify_timer_.async_wait(
[&](const boost::system::error_code &) { wait_for_host_connection(); });
host_notify_timer_.async_wait([&](const boost::system::error_code &) { wait_for_host_connection(); });
}
}
......@@ -153,11 +161,9 @@ void AdbMessageProcessor::read_next_host_message() {
boost::asio::buffer(host_buffer_));
}
void AdbMessageProcessor::on_host_read_size(
const boost::system::error_code &error, std::size_t bytes_read) {
void AdbMessageProcessor::on_host_read_size(const boost::system::error_code &error, std::size_t bytes_read) {
if (error) {
state_ = closed_by_host;
messenger_->close();
return;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册