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

[EchoServer] set SO_REUSEPORT on the listen socket

This is needed by emper-io-eval because apparently our startup/termination
times are shorter than the OS allows the rebinding of the same tcp tuple.

Also make all global variables static because they don't have to be exported.
parent ebd3f04f
No related branches found
No related tags found
No related merge requests found
......@@ -21,12 +21,13 @@
#include <compare>
#endif
const std::string HOST = "::";
const std::string PORT = "12345";
static const std::string HOST = "::";
static const std::string PORT = "12345";
static const int BACKLOG = 1024;
unsigned int computations_us = 0;
static unsigned int computations_us = 0;
std::atomic<bool> quit = false;
static std::atomic<bool> quit = false;
auto main(int argc, char* argv[]) -> int {
std::string host = HOST;
......@@ -48,7 +49,7 @@ auto main(int argc, char* argv[]) -> int {
std::cout << "Echoserver listening on " << host << ":" << port << std::endl;
Runtime runtime;
auto* listener = emper::io::tcp_listener(host, port, [](int socket) {
auto serverFunc = [](int socket) {
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char buf[1024];
while (!quit.load(std::memory_order_consume)) {
......@@ -83,7 +84,10 @@ auto main(int argc, char* argv[]) -> int {
}
emper::io::closeAndForget(socket);
});
};
auto* listener =
emper::io::tcp_listener(host, port, serverFunc, BACKLOG, {emper::io::SockOpt::ReusePort});
if (!listener) {
exit(EXIT_FAILURE);
......
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