From 926613d4641e2de1b55b2fd4cbd906fb629de69c Mon Sep 17 00:00:00 2001 From: Pierre-Hugues Husson Date: Sat, 20 Mar 2021 21:55:07 +0100 Subject: [PATCH] [simg2img_simple] Abandon splice if it's too slow. --- cmds/simg2img_simple.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmds/simg2img_simple.cpp b/cmds/simg2img_simple.cpp index d6640de..6b783fb 100644 --- a/cmds/simg2img_simple.cpp +++ b/cmds/simg2img_simple.cpp @@ -41,10 +41,17 @@ typedef struct chunk_header { * For a CRC32 chunk, it's 4 bytes of CRC32 */ +static int disable_splice = 0; void nsendfile(int out_fd, int in_fd, size_t count) { char buf[1024*1024]; while(count) { - ssize_t res = splice(in_fd, NULL, out_fd, NULL, count, 0); + ssize_t res = -1; + if(!disable_splice) { + res = splice(in_fd, NULL, out_fd, NULL, count, 0); + } + + if(count > 16*1024 && res < 1024) + disable_splice = 1; if(res==-1) { ssize_t sizeToRead = sizeof(buf); if(count < sizeToRead) sizeToRead = count;