diff --git a/apps/EchoServer.cpp b/apps/EchoServer.cpp index e0c96ef13f18961e94533e9c0cd6db25fb3f4563..683b92653ea4e16b06111ad9761bae0f6dce49b8 100644 --- a/apps/EchoServer.cpp +++ b/apps/EchoServer.cpp @@ -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));