Something went wrong on our end
Select Git revision
file_contexts
-
xshu authored
we are aiming to improve logging performance by having wifi hal directly write to the flash. Wifi hal need to be able to create, write, and delete files in a directory. This will be restricted to userdebug and eng builds only. Bug: 70170285 Test: compile, run on device Change-Id: Id0cd317411f4c393d7529aa31b501046d7350edb
xshu authoredwe are aiming to improve logging performance by having wifi hal directly write to the flash. Wifi hal need to be able to create, write, and delete files in a directory. This will be restricted to userdebug and eng builds only. Bug: 70170285 Test: compile, run on device Change-Id: Id0cd317411f4c393d7529aa31b501046d7350edb
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;
}