]> git.ipfire.org Git - fireperf.git/commitdiff
client: Give the user the choice whether to send random data or zero
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 28 Jan 2021 11:07:04 +0000 (11:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 28 Jan 2021 11:07:04 +0000 (11:07 +0000)
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 <michael.tremer@ipfire.org>
src/client.c
src/main.c
src/main.h

index 1d4f4080674c4240ae84ee5445035afa09fe184a..f1bc97fe840d5959b774547baefdcb4a14ab734c 100644 (file)
@@ -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));
index 69f38ae2531fed9969cfca92078c1ac1ed494006..a1fc96ad2979b997170c35054d9845687634e06a 100644 (file)
@@ -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;
index 62e930169194cef82ea06357038dafce828c2854..b5eed86f77d97c1e317acae8a5d87a8ccbf65473 100644 (file)
@@ -47,6 +47,7 @@ struct fireperf_config {
        int port;
        unsigned long parallel;
        unsigned int timeout;
+       int zero;
 };
 
 #endif /* FIREPERF_MAIN_H */