From: Michael Tremer Date: Wed, 20 Oct 2021 18:15:33 +0000 (+0000) Subject: Enable ZEROCOPY X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=326ee97b34082bf690493e54f9233d089b9b296b;p=fireperf.git Enable ZEROCOPY https://www.kernel.org/doc/html/latest/networking/msg_zerocopy.html Signed-off-by: Michael Tremer --- diff --git a/src/main.c b/src/main.c index 3af95bc..1d996cd 100644 --- a/src/main.c +++ b/src/main.c @@ -459,7 +459,7 @@ int handle_connection_send(struct fireperf_config* conf, } do { - bytes_sent = send(fd, buffer, SOCKET_SEND_BUFFER_SIZE, 0); + bytes_sent = send(fd, buffer, SOCKET_SEND_BUFFER_SIZE, MSG_ZEROCOPY); } while (bytes_sent < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)); // Update statistics diff --git a/src/server.c b/src/server.c index e332b2d..19cc345 100644 --- a/src/server.c +++ b/src/server.c @@ -102,6 +102,14 @@ static int create_socket(struct fireperf_config* conf, int i) { goto ERROR; } + // Enable zero-copy + r = setsockopt(fd, SOL_SOCKET, SO_ZEROCOPY, &flags, sizeof(flags)); + if (r) { + ERROR(conf, "Could not set SO_ZEROCOPY on socket %d: %s\n", + fd, strerror(errno)); + goto ERROR; + } + // Set socket buffer sizes r = set_socket_buffer_sizes(conf, fd); if (r)