]> git.ipfire.org Git - fireperf.git/commitdiff
client: Implement closing connections straight away
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Feb 2021 15:01:34 +0000 (15:01 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 4 Feb 2021 15:01:34 +0000 (15:01 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
man/fireperf.txt
src/client.c
src/main.c
src/main.h

index bbe69dcd126eb292ea1dc7cd18534557e1b2decb..83969fcdd2222bcfdcbd0de9c98031299a0debd9 100644 (file)
@@ -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
index 7770c5c42c239bbe3ebab4b46bc2365e01ebfcb9..53c93daff8df0055293b2bb278d4b23e29be6a62 100644 (file)
@@ -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;
                                }
index 6eb9d89a31543accca7ef8d4dc1cfe22c5928d72..7d16aa9545a20dfad624ad8329e48ed4a96a367b 100644 (file)
@@ -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;
index cbcebab8aa58a32fc3924db00eb4da9b66cfafe1..8e821179254788c2f3fbe8f590e4e42091d71510 100644 (file)
@@ -60,6 +60,7 @@ struct fireperf_config {
        unsigned int listening_sockets;
        unsigned long parallel;
        unsigned int timeout;
+       int close;
        int zero;
 };