]> git.ipfire.org Git - fireperf.git/commitdiff
Change that the server is now sending data and the client is receiving it
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Feb 2021 16:10:16 +0000 (16:10 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Feb 2021 16:10:16 +0000 (16:10 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/client.c
src/main.c
src/server.c

index d92c6e1c8abe8910d5dc7f5cbe7f3253348365be..1354c3ff983b04f687b653738d2fe7348d9f297d 100644 (file)
@@ -161,9 +161,9 @@ int fireperf_client(struct fireperf_config* conf, struct fireperf_stats* stats,
        };
        struct epoll_event events[EPOLL_MAX_EVENTS];
 
-       // Let us know when the socket is ready for sending data
+       // Let us know when the socket is ready for receiving data
        if (!conf->keepalive_only)
-               ev.events |= EPOLLOUT;
+               ev.events |= EPOLLIN;
 
        DEBUG(conf, "Opening %lu connections...\n", conf->parallel);
 
@@ -239,11 +239,20 @@ int fireperf_client(struct fireperf_config* conf, struct fireperf_stats* stats,
                                        close(fd);
 
                                        stats->open_connections--;
+                               } else {
+                                       // Handle incoming data
+                                       if (events[i].events & EPOLLIN) {
+                                               r = handle_connection_recv(conf, stats, fd);
+                                               if (r < 0)
+                                                       goto ERROR;
+                                       }
 
-                               } else if (events[i].events & EPOLLOUT) {
-                                       r = handle_connection_ready(conf, stats, fd);
-                                       if (r)
-                                               goto ERROR;
+                                       // Handle outgoing data
+                                       if (events[i].events & EPOLLOUT) {
+                                               r = handle_connection_ready(conf, stats, fd);
+                                               if (r)
+                                                       goto ERROR;
+                                       }
                                }
                        }
                }
index db4a23bae99370462cae8283a091e5eae3f55782..b6a551de3407a6eaca04540cfe29f929c773055a 100644 (file)
@@ -373,11 +373,11 @@ int fireperf_dump_stats(struct fireperf_config* conf, struct fireperf_stats* sta
        char* bps = NULL;
        switch (mode) {
                case FIREPERF_MODE_CLIENT:
-                       bps = format_size(stats->bytes_sent * 8 / delta, FIREPERF_FORMAT_BITS);
+                       bps = format_size(stats->bytes_received * 8 / delta, FIREPERF_FORMAT_BITS);
                        break;
 
                case FIREPERF_MODE_SERVER:
-                       bps = format_size(stats->bytes_received * 8 / delta, FIREPERF_FORMAT_BITS);
+                       bps = format_size(stats->bytes_sent * 8 / delta, FIREPERF_FORMAT_BITS);
                        break;
        }
 
@@ -390,13 +390,13 @@ int fireperf_dump_stats(struct fireperf_config* conf, struct fireperf_stats* sta
        char* total_bytes = NULL;
        switch (mode) {
                case FIREPERF_MODE_CLIENT:
-                       total_bytes = format_size(stats->total_bytes_sent, FIREPERF_FORMAT_BYTES);
-                       INFO(conf, "  %-20s: %20s\n", "Total Bytes Sent", total_bytes);
+                       total_bytes = format_size(stats->total_bytes_received, FIREPERF_FORMAT_BYTES);
+                       INFO(conf, "  %-20s: %20s\n", "Total Bytes Received", total_bytes);
                        break;
 
                case FIREPERF_MODE_SERVER:
-                       total_bytes = format_size(stats->total_bytes_received, FIREPERF_FORMAT_BYTES);
-                       INFO(conf, "  %-20s: %20s\n", "Total Bytes Received", total_bytes);
+                       total_bytes = format_size(stats->total_bytes_sent, FIREPERF_FORMAT_BYTES);
+                       INFO(conf, "  %-20s: %20s\n", "Total Bytes Sent", total_bytes);
                        break;
        }
 
index 9253c1d084f658abc99ce09ae33dbb216fa564a7..b090b135506701bf2cfbb286a8418206af004d25 100644 (file)
@@ -171,7 +171,7 @@ int fireperf_server(struct fireperf_config* conf, struct fireperf_stats* stats,
                                        goto ERROR;
 
                                // Add the new socket to epoll()
-                               ev.events  = EPOLLIN|EPOLLRDHUP;
+                               ev.events  = EPOLLOUT|EPOLLRDHUP;
                                ev.data.fd = connfd;
 
                                if (epoll_ctl(epollfd, EPOLL_CTL_ADD, connfd, &ev)) {
@@ -220,12 +220,19 @@ int fireperf_server(struct fireperf_config* conf, struct fireperf_stats* stats,
                                        continue;
                                }
 
-                               // One of the connections had IO
+                               // Handle incoming data
                                if (events[i].events & EPOLLIN) {
                                        r = handle_connection_recv(conf, stats, fd);
                                        if (r < 0)
                                                goto ERROR;
                                }
+
+                               // Handle outgoing data
+                               if (events[i].events & EPOLLOUT) {
+                                       r = handle_connection_send(conf, stats, fd);
+                                       if (r < 0)
+                                               goto ERROR;
+                               }
                        }
                }
        }