diff --git a/include/common/defaults.h b/include/common/defaults.h index d1ce0214c..96e0f61b4 100644 --- a/include/common/defaults.h +++ b/include/common/defaults.h @@ -97,6 +97,12 @@ #define MIN_RET_FOR_READ_LOOP 1460 #endif +// The minimum number of bytes to be forwarded that is worth trying to splice. +// Below 4kB, it's not worth allocating pipes nor pretending to zero-copy. +#ifndef MIN_SPLICE_FORWARD +#define MIN_SPLICE_FORWARD 4096 +#endif + // the max number of events returned in one call to poll/epoll. Too small a // value will cause lots of calls, and too high a value may cause high latency. #ifndef MAX_POLL_EVENTS diff --git a/src/stream_sock.c b/src/stream_sock.c index 5539cd205..d4752845d 100644 --- a/src/stream_sock.c +++ b/src/stream_sock.c @@ -280,7 +280,7 @@ int stream_sock_read(int fd) { goto out_wakeup; #if defined(CONFIG_HAP_LINUX_SPLICE) - if (b->to_forward && b->flags & BF_KERN_SPLICING) { + if (b->to_forward >= MIN_SPLICE_FORWARD && b->flags & BF_KERN_SPLICING) { /* Under Linux, if FD_POLL_HUP is set, we have reached the end. * Since older splice() implementations were buggy and returned