From: Michael Tremer Date: Thu, 28 Jan 2021 11:07:04 +0000 (+0000) Subject: client: Give the user the choice whether to send random data or zero X-Git-Tag: 0.1.0~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4600c23a2410c37db52ad25f5d21d12ba190770;p=fireperf.git client: Give the user the choice whether to send random data or zero This is useful when compression is being used on the link since random data cannot be compressed, but the zeroes can. Signed-off-by: Michael Tremer --- diff --git a/src/client.c b/src/client.c index 1d4f408..f1bc97f 100644 --- a/src/client.c +++ b/src/client.c @@ -60,12 +60,21 @@ static int connect_socket(struct fireperf_config* conf, int fd) { return 0; } +static void randomize_buffer(char* buffer, size_t s) { + return; // TODO +} + static int send_data_to_server(struct fireperf_config* conf, int fd) { - char buffer[BUFFER_SIZE]; + char buffer[BUFFER_SIZE] = { 0 }; ssize_t bytes_sent; DEBUG(conf, "Sending %zu bytes of data to server\n", sizeof(buffer)); + // Randomize the buffer if requested, otherwise just send an empty buffer + if (!conf->zero) { + randomize_buffer(buffer, sizeof(buffer)); + } + do { bytes_sent = send(fd, buffer, sizeof(buffer), 0); } while (bytes_sent < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)); diff --git a/src/main.c b/src/main.c index 69f38ae..a1fc96a 100644 --- a/src/main.c +++ b/src/main.c @@ -62,6 +62,7 @@ static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { {"port", required_argument, 0, 'p'}, {"server", no_argument, 0, 's'}, {"timeout", required_argument, 0, 't'}, + {"zero", no_argument, 0, 'z'}, {0, 0, 0, 0}, }; @@ -69,7 +70,7 @@ static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { int done = 0; while (!done) { - int c = getopt_long(argc, argv, "c:dp:st:P:", long_options, &option_index); + int c = getopt_long(argc, argv, "c:dp:st:zP:", long_options, &option_index); // End if (c == -1) @@ -135,6 +136,10 @@ static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { conf->timeout = strtoul(optarg, NULL, 10); break; + case 'z': + conf->zero = 1; + break; + default: done = 1; break; diff --git a/src/main.h b/src/main.h index 62e9301..b5eed86 100644 --- a/src/main.h +++ b/src/main.h @@ -47,6 +47,7 @@ struct fireperf_config { int port; unsigned long parallel; unsigned int timeout; + int zero; }; #endif /* FIREPERF_MAIN_H */