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
No related merge requests found
Pipeline #59215 passed
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <cerrno> #include <cerrno>
#include <chrono>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
...@@ -12,17 +13,24 @@ ...@@ -12,17 +13,24 @@
#include "Common.hpp" #include "Common.hpp"
#include "Debug.hpp" #include "Debug.hpp"
#include "Runtime.hpp" #include "Runtime.hpp"
#include "emper-config.h"
#include "io.hpp" #include "io.hpp"
#ifdef EMPER_HAS_COMPARE_H
#include <compare>
#endif
const std::string HOST = "::"; const std::string HOST = "::";
const std::string PORT = "12345"; const std::string PORT = "12345";
unsigned int computations_us = 0;
auto main(int argc, char* argv[]) -> int { auto main(int argc, char* argv[]) -> int {
std::string host = HOST; std::string host = HOST;
std::string port = PORT; std::string port = PORT;
if (argc > 2) { if (argc > 3) {
std::cerr << "Usage: " << argv[0] << " [port]" << std::endl; std::cerr << "Usage: " << argv[0] << " [port] [computation_us]" << std::endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -30,6 +38,10 @@ auto main(int argc, char* argv[]) -> int { ...@@ -30,6 +38,10 @@ auto main(int argc, char* argv[]) -> int {
port = std::string(argv[1]); port = std::string(argv[1]);
} }
if (argc > 2) {
computations_us = std::stoi(argv[2]);
}
std::cout << "Echoserver listening on " << host << ":" << port << std::endl; std::cout << "Echoserver listening on " << host << ":" << port << std::endl;
Runtime runtime; Runtime runtime;
...@@ -53,6 +65,14 @@ auto main(int argc, char* argv[]) -> int { ...@@ -53,6 +65,14 @@ auto main(int argc, char* argv[]) -> int {
exit(EXIT_SUCCESS); 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); ssize_t bytes_send = emper::io::sendAndWait(socket, buf, bytes_recv, MSG_NOSIGNAL, true);
if (unlikely(bytes_recv != bytes_send)) { if (unlikely(bytes_recv != bytes_send)) {
LOGE("server send failed: " << strerror(errno)); 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