From: Michael Tremer Date: Thu, 4 Feb 2021 15:01:34 +0000 (+0000) Subject: client: Implement closing connections straight away X-Git-Tag: 0.1.0~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=78071ac7bde641d97e3ce69225ba5cb7a22f2210;p=fireperf.git client: Implement closing connections straight away Signed-off-by: Michael Tremer --- diff --git a/man/fireperf.txt b/man/fireperf.txt index bbe69dc..83969fc 100644 --- a/man/fireperf.txt +++ b/man/fireperf.txt @@ -75,6 +75,13 @@ a network between a fireperf client and fireperf server. If set, the client will automatically terminate itself after T seconds. Otherwise it will run for forever. +--close:: +-x:: + If set, all connections will be closed as soon as they have been established. + No data will be sent. + + + This is useful to test how many TCP handshakes per second are possible. + --zero:: -z:: Instead of sending random data, this option will set the client to send packets diff --git a/src/client.c b/src/client.c index 7770c5c..53c93da 100644 --- a/src/client.c +++ b/src/client.c @@ -209,6 +209,21 @@ static int send_data_to_server(struct fireperf_config* conf, return 0; } +static int handle_connection_ready(struct fireperf_config* conf, + struct fireperf_stats* stats, int fd, struct fireperf_random_pool* pool) { + // Are we supposed to close this connection straight away? + if (conf->close) { + DEBUG(conf, "Closing connection %d\n", fd); + close(fd); + + stats->open_connections--; + + return 0; + } + + return send_data_to_server(conf, stats, fd, pool); +} + int fireperf_client(struct fireperf_config* conf, struct fireperf_stats* stats, int epollfd, int timerfd) { struct fireperf_random_pool* pool = NULL; @@ -311,7 +326,7 @@ int fireperf_client(struct fireperf_config* conf, struct fireperf_stats* stats, stats->open_connections--; } else if (events[i].events & EPOLLOUT) { - r = send_data_to_server(conf, stats, fd, pool); + r = handle_connection_ready(conf, stats, fd, pool); if (r) goto ERROR; } diff --git a/src/main.c b/src/main.c index 6eb9d89..7d16aa9 100644 --- a/src/main.c +++ b/src/main.c @@ -125,6 +125,7 @@ static int set_limits(struct fireperf_config* conf) { static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { static struct option long_options[] = { {"client", required_argument, 0, 'c'}, + {"close", no_argument, 0, 'x'}, {"debug", no_argument, 0, 'd'}, {"keepalive", no_argument, 0, 'k'}, {"parallel", required_argument, 0, 'P'}, @@ -140,7 +141,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:dkp:st:zP:V", long_options, &option_index); + int c = getopt_long(argc, argv, "c:dkp:st:xzP:V", long_options, &option_index); // End if (c == -1) @@ -222,6 +223,10 @@ static int parse_argv(int argc, char* argv[], struct fireperf_config* conf) { conf->timeout = strtoul(optarg, NULL, 10); break; + case 'x': + conf->close = 1; + break; + case 'z': conf->zero = 1; break; diff --git a/src/main.h b/src/main.h index cbcebab..8e82117 100644 --- a/src/main.h +++ b/src/main.h @@ -60,6 +60,7 @@ struct fireperf_config { unsigned int listening_sockets; unsigned long parallel; unsigned int timeout; + int close; int zero; };