Something went wrong on our end
Select Git revision
-
Alex Deymo authored
The recovery flow for A/B devices allows to sideload an OTA downloaded to a desktop and apply from recovery. This patch allows the "recovery" context to perform all the operations required to apply an update as update_engine would do in the background. These rules are now extracted into a new attributte called update_engine_common shared between recovery and update_engine. Bug: 27178350 (cherry picked from commit d63084d3) Change-Id: I1f3e1e83a21e37e09b69cd9c497f87b42b9cbeb1
Alex Deymo authoredThe recovery flow for A/B devices allows to sideload an OTA downloaded to a desktop and apply from recovery. This patch allows the "recovery" context to perform all the operations required to apply an update as update_engine would do in the background. These rules are now extracted into a new attributte called update_engine_common shared between recovery and update_engine. Bug: 27178350 (cherry picked from commit d63084d3) Change-Id: I1f3e1e83a21e37e09b69cd9c497f87b42b9cbeb1
EchoServer.cpp 2.35 KiB
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020-2021 Florian Fischer
#include <sys/socket.h>
#include <sys/types.h>
#include <atomic>
#include <cerrno>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include "Common.hpp"
#include "Debug.hpp"
#include "Runtime.hpp"
#include "emper-config.h"
#include "io.hpp"
#ifdef EMPER_HAS_COMPARE_H
#include <compare>
#endif
const std::string HOST = "::";
const std::string PORT = "12345";
unsigned int computations_us = 0;
std::atomic<bool> quit = false;
auto main(int argc, char* argv[]) -> int {
std::string host = HOST;
std::string port = PORT;
if (argc > 3) {
std::cerr << "Usage: " << argv[0] << " [port] [computation_us]" << std::endl;
exit(EXIT_FAILURE);
}
if (argc > 1) {
port = std::string(argv[1]);
}
if (argc > 2) {
computations_us = std::stoi(argv[2]);
}
std::cout << "Echoserver listening on " << host << ":" << port << std::endl;
Runtime runtime;
auto* listener = emper::io::tcp_listener(host, port, [](int socket) {
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char buf[1024];
while (!quit.load(std::memory_order_consume)) {
ssize_t bytes_recv = emper::io::recvAndWait(socket, buf, sizeof(buf), 0);
if (unlikely(bytes_recv <= 0)) {
// socket was shutdown
if (bytes_recv < 0) {
LOGE("server read failed:" << strerror(errno));
}
break;
}
if (unlikely(bytes_recv == 5 && strncmp("quit\n", buf, bytes_recv) == 0)) {
quit = true;
std::cout << "Echoserver received 'quit' command from client" << std::endl;
Runtime::getRuntime()->initiateTermination();
break;
}
const auto start = std::chrono::steady_clock::now();
const auto deadline = start + std::chrono::microseconds(computations_us);
// TODO: The suppressed linter error below may be a false positive
// reported by clang-tidy.
// NOLINTNEXTLINE(modernize-use-nullptr)
while (std::chrono::steady_clock::now() < deadline) {
}
ssize_t bytes_send = emper::io::sendAndWait(socket, buf, bytes_recv, MSG_NOSIGNAL, true);
if (unlikely(bytes_recv != bytes_send)) {
LOGE("server send failed: " << strerror(errno));
break;
}
}
emper::io::closeAndForget(socket);
});
if (!listener) {
exit(EXIT_FAILURE);
}
runtime.scheduleFromAnywhere(*listener);
runtime.waitUntilFinished();
return EXIT_FAILURE;
}