Skip to content

Instantly share code, notes, and snippets.

@kazuho
Created February 8, 2023 02:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuho/2e4a4bc02792bc9c5f622b1a4d43caf2 to your computer and use it in GitHub Desktop.
Save kazuho/2e4a4bc02792bc9c5f622b1a4d43caf2 to your computer and use it in GitHub Desktop.
iperf3 splice patch
diff --git a/src/iperf_api.c b/src/iperf_api.c
index 09ab6af..a54be44 100644
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -4520,11 +4520,26 @@ diskfile_recv(struct iperf_stream *sp)
{
int r;
+#if 1
+ static int pipefds[2] = {-1, -1};
+ if (pipefds[0] == -1)
+ pipe(pipefds);
+ r = splice(sp->socket, NULL, pipefds[1], NULL, sp->settings->blksize, SPLICE_F_NONBLOCK);
+ if (r > 0 && sp->test->state == TEST_RUNNING) {
+ splice(pipefds[0], NULL, sp->diskfile_fd, NULL, r, 0);
+ sp->result->bytes_received += r;
+ sp->result->bytes_received_this_interval += r;
+ }
+ if (r < 0) {
+ perror("Hmmm");
+ }
+#else
r = sp->rcv2(sp);
if (r > 0) {
// NOTE: Currently ignoring the return value of writing to disk
(void) (write(sp->diskfile_fd, sp->buffer, r) + 1);
}
+#endif
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment