Make adb message processor more robust in shutdown scenarios
This commit is contained in:
parent
14d77e9cc4
commit
183c02d2d0
1 changed files with 13 additions and 7 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue