From 4b4fbbb501a74d0949e52e16ceeaebaa8df68b84 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 18 Feb 2021 16:10:16 +0000 Subject: [PATCH] Change that the server is now sending data and the client is receiving it Signed-off-by: Michael Tremer --- src/client.c | 21 +++++++++++++++------ src/main.c | 12 ++++++------ src/server.c | 11 +++++++++-- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/client.c b/src/client.c index d92c6e1..1354c3f 100644 --- a/src/client.c +++ b/src/client.c @@ -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; + } } } } diff --git a/src/main.c b/src/main.c index db4a23b..b6a551d 100644 --- a/src/main.c +++ b/src/main.c @@ -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; } diff --git a/src/server.c b/src/server.c index 9253c1d..b090b13 100644 --- a/src/server.c +++ b/src/server.c @@ -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; + } } } } -- 2.47.3