Skip to content
Snippets Groups Projects
Select Git revision
  • 35a0597a17a8111631fb17b3464a635bb429a9df
  • master default protected
  • android-7.1.2_r28_klist
  • pie-cts-release
  • pie-vts-release
  • pie-cts-dev
  • oreo-mr1-iot-release
  • sdk-release
  • oreo-m6-s4-release
  • oreo-m4-s12-release
  • pie-release
  • pie-r2-release
  • pie-r2-s1-release
  • oreo-vts-release
  • oreo-cts-release
  • oreo-dev
  • oreo-mr1-dev
  • pie-gsi
  • pie-platform-release
  • pie-dev
  • oreo-cts-dev
  • android-o-mr1-iot-release-1.0.4
  • android-9.0.0_r8
  • android-9.0.0_r7
  • android-9.0.0_r6
  • android-9.0.0_r5
  • android-8.1.0_r46
  • android-8.1.0_r45
  • android-n-iot-release-smart-display-r2
  • android-vts-8.1_r5
  • android-cts-8.1_r8
  • android-cts-8.0_r12
  • android-cts-7.1_r20
  • android-cts-7.0_r24
  • android-o-mr1-iot-release-1.0.3
  • android-cts-9.0_r1
  • android-8.1.0_r43
  • android-8.1.0_r42
  • android-n-iot-release-smart-display
  • android-p-preview-5
  • android-9.0.0_r3
41 results

attributes

Blame
    • Alex Deymo's avatar
      27f19427
      Allow executing update_engine_sideload from recovery. · 27f19427
      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
      27f19427
      History
      Allow executing update_engine_sideload from recovery.
      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
    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;
    }