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

[IO] add output file support to echoclient

This is useful for my evaluation. Because with an output file I
just have to check if it exists to see if an echoclient execution was
successful.
parent e1722b7e
No related branches found
No related tags found
1 merge request!1WIP: Emper shutdown
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2021 Florian Fischer
#include <fcntl.h>
#include <netdb.h> //for getaddrinfo
#include <sys/socket.h> // for shutdown, socket, AF_INET
#include <sys/stat.h>
#include <unistd.h>
#include <algorithm> // for find
#include <atomic>
......@@ -158,7 +161,7 @@ static auto existsOption(int argc, char** argv, const std::string& option) -> bo
static void printUsage(char* name) {
std::cerr << "Usage: " << name
<< "[-h] [-p <port>] [-c <clients>] [-i <iterations>] [-a <address>] [-s <size>] [-b "
"<server backlog>]"
"<server backlog>] [-f <output-file>]"
<< std::endl;
}
......@@ -198,6 +201,17 @@ auto main(int argc, char* argv[]) -> int {
server_backlog = strtol(server_backlog_s, nullptr, DECIMAL);
}
int out_fd = STDOUT_FILENO;
char* output_file = getOption(argc, argv, "-f");
if (output_file) {
out_fd = open(output_file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
if (out_fd < 0) {
DIE_MSG_ERRNO("opening output file failed");
}
}
int err = getaddrinfo(host.c_str(), port.c_str(), nullptr, &server);
if (err) {
if (err == EAI_SYSTEM) {
......@@ -246,8 +260,19 @@ auto main(int argc, char* argv[]) -> int {
avg_ns /= 2;
}
std::cout << "clients,iterations,size,time" << std::endl;
std::cout << clients << "," << iterations << "," << size << "," << avg_ns << std::endl;
std::stringstream sst;
sst << "clients,iterations,size,time" << std::endl;
sst << clients << "," << iterations << "," << size << "," << avg_ns << std::endl;
auto output = sst.str();
if (emper::io::writeFileAndWait(out_fd, output.c_str(), output.size()) < 0) {
DIE_MSG_ERRNO("writing results failed");
}
if (output_file) {
emper::io::closeAndForget(out_fd);
}
delete[] client_avgs;
exit(EXIT_SUCCESS);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment