Advance send buffer in xsendfile for conservative method. - geomyidae - A small C-based gopherd. HTML git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 74efed84eb2e5cc3f5b72be8b112020a362e7232 DIR parent e9292b7acff19655482c6b53ff19f8c51f06bdcd HTML Author: Christoph Lohmann <20h@r-36.net> Date: Wed, 7 Feb 2018 20:17:56 +0100 Advance send buffer in xsendfile for conservative method. Thanks Lucas Gabriel Vuotto <lgv@nanashi.co>! Diffstat: M ind.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- DIR diff --git a/ind.c b/ind.c @@ -78,7 +78,7 @@ int xsendfile(int fd, int sock) { struct stat st; - char *sendb; + char *sendb, *sendi; size_t bufsiz = BUFSIZ, count = 0; int len, sent, optval; @@ -121,12 +121,14 @@ xsendfile(int fd, int sock) if (count > 0) { sendb = xmalloc(bufsiz); while ((len = read(fd, sendb, bufsiz)) > 0) { + sendi = sendb; while (len > 0) { - if ((sent = send(sock, sendb, len, 0)) < 0) { + if ((sent = send(sock, sendi, len, 0)) < 0) { free(sendb); return -1; } len -= sent; + sendi += sent; } } free(sendb);