Skip to content
Snippets Groups Projects
Commit 1e6510ae authored by Florian Fischer's avatar Florian Fischer
Browse files

[EchoServer] add configurable computation part in us spent busy looping

parent c8828c26
No related branches found
No related tags found
1 merge request!124[EchoServer] add configurable computation part in us spent busy looping
......@@ -4,6 +4,7 @@
#include <sys/types.h>
#include <cerrno>
#include <chrono>
#include <cstdlib>
#include <cstring>
#include <iostream>
......@@ -12,17 +13,24 @@
#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;
auto main(int argc, char* argv[]) -> int {
std::string host = HOST;
std::string port = PORT;
if (argc > 2) {
std::cerr << "Usage: " << argv[0] << " [port]" << std::endl;
if (argc > 3) {
std::cerr << "Usage: " << argv[0] << " [port] [computation_us]" << std::endl;
exit(EXIT_FAILURE);
}
......@@ -30,6 +38,10 @@ auto main(int argc, char* argv[]) -> int {
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;
......@@ -53,6 +65,14 @@ auto main(int argc, char* argv[]) -> int {
exit(EXIT_SUCCESS);
}
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));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment