From 95ee7db5839176a352969e8bc99afba20d13bc85 Mon Sep 17 00:00:00 2001 From: David Bar-On Date: Tue, 11 Jun 2024 22:08:04 +0300 Subject: [PATCH] Changes per reviewer comments and cleaning --- src/iperf_api.c | 14 +++++++++++--- src/iperf_api.h | 1 + src/iperf_error.c | 3 +++ src/iperf_udp.c | 1 + src/net.c | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/iperf_api.c b/src/iperf_api.c index c69fe52fb..912638f67 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -1489,7 +1489,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) i_errno = IENOSENDFILE; return -1; } - test->zerocopy = 1; + test->zerocopy = ZEROCOPY_TCP_SENDFILE; #endif /* HAVE_MSG_ZEROCOPY */ client_flag = 1; break; @@ -1767,13 +1767,21 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) } #if defined(HAVE_MSG_ZEROCOPY) - // sero copy for TCP use sendfile() + // UDP supports "zero copy" only using MSG_ZEROCOPY + if (test->protocol->id == Pudp && test->zerocopy) + test->zerocopy = ZEROCOPY_TCP_MSG_ZEROCOPY; + // Zero copy for TCP use sendfile() if (test->zerocopy && test->protocol->id != Pudp && !has_sendfile()) { i_errno = IENOSENDFILE; return -1; } + // Using MSG_ZEROCOPY is not supported when disk file is used + if (test->diskfile_name != (char*) 0 && test->zerocopy == ZEROCOPY_TCP_MSG_ZEROCOPY) { + i_errno = IEDISKFILEZEROCOPY; + return -1; + } #else - // sero copy is supported only by TCP + // Zero copy is supported only by TCP if (test->zerocopy && test->protocol->id != Ptcp) { i_errno = IENOSENDFILE; return -1; diff --git a/src/iperf_api.h b/src/iperf_api.h index 4de7487f4..132bbc666 100644 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -420,6 +420,7 @@ enum { IESNDTIMEOUT = 33, // Illegal message send timeout IEUDPFILETRANSFER = 34, // Cannot transfer file using UDP IESERVERAUTHUSERS = 35, // Cannot access authorized users file + IEDISKFILEZEROCOPY = 36, // Sending disk file using MSG_ZEROCOPY is not supported /* Test errors */ IENEWTEST = 100, // Unable to create a new test (check perror) IEINITTEST = 101, // Test initialization failed (check perror) diff --git a/src/iperf_error.c b/src/iperf_error.c index 59edce7e2..8825f7c4f 100644 --- a/src/iperf_error.c +++ b/src/iperf_error.c @@ -215,6 +215,9 @@ iperf_strerror(int int_errno) snprintf(errstr, len, "this OS does not support sendfile"); #endif /* HAVE_MSG_ZEROCOPY */ break; + case IEDISKFILEZEROCOPY: + snprintf(errstr, len, "Sending disk file using MSG_ZEROCOPY is not supported"); + break; case IEOMIT: snprintf(errstr, len, "bogus value for --omit"); break; diff --git a/src/iperf_udp.c b/src/iperf_udp.c index 39b80e4b7..53333d37c 100644 --- a/src/iperf_udp.c +++ b/src/iperf_udp.c @@ -459,6 +459,7 @@ iperf_udp_accept(struct iperf_test *test) /* * Create a new "listening" socket to replace the one we were using before. */ + FD_CLR(test->prot_listener, &test->read_set); // No control messages from old listener test->prot_listener = netannounce(test->settings->domain, Pudp, test->bind_address, test->bind_dev, test->server_port); if (test->prot_listener < 0) { i_errno = IESTREAMLISTEN; diff --git a/src/net.c b/src/net.c index ca33e094e..29b8d3343 100644 --- a/src/net.c +++ b/src/net.c @@ -428,7 +428,7 @@ Nrecv(int fd, char *buf, size_t count, int prot, int sock_opt) while (nleft > 0) { if (sock_opt) - r = recv(fd, buf, nleft, MSG_TRUNC); + r = recv(fd, buf, nleft, sock_opt); else r = read(fd, buf, nleft);