iAdd the story of xsendfile to the source. - geomyidae - A small C-based gopherd. Err bitreich.org 70 hgit clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/ URL:git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/geomyidae/ bitreich.org 70 1Log /scm/geomyidae/log.gph bitreich.org 70 1Files /scm/geomyidae/files.gph bitreich.org 70 1Refs /scm/geomyidae/refs.gph bitreich.org 70 1Tags /scm/geomyidae/tag bitreich.org 70 1README /scm/geomyidae/file/README.gph bitreich.org 70 1LICENSE /scm/geomyidae/file/LICENSE.gph bitreich.org 70 i--- Err bitreich.org 70 1commit bbda3db127acc7e916bdd1668edb00ca7235ad02 /scm/geomyidae/commit/bbda3db127acc7e916bdd1668edb00ca7235ad02.gph bitreich.org 70 1parent 4481c2cbcf4bb258d8f06785528c0387386064ca /scm/geomyidae/commit/4481c2cbcf4bb258d8f06785528c0387386064ca.gph bitreich.org 70 hAuthor: Christoph Lohmann <20h@r-36.net> URL:mailto:20h@r-36.net bitreich.org 70 iDate: Sat, 30 Jan 2021 18:28:55 +0100 Err bitreich.org 70 i Err bitreich.org 70 iAdd the story of xsendfile to the source. Err bitreich.org 70 i Err bitreich.org 70 iDiffstat: Err bitreich.org 70 i M ind.c | 21 ++++++++++++++++++++- Err bitreich.org 70 i Err bitreich.org 70 i1 file changed, 20 insertions(+), 1 deletion(-) Err bitreich.org 70 i--- Err bitreich.org 70 1diff --git a/ind.c b/ind.c /scm/geomyidae/file/ind.c.gph bitreich.org 70 i@@ -116,9 +116,27 @@ xsendfile(int fd, int sock) Err bitreich.org 70 i Err bitreich.org 70 i USED(optval); Err bitreich.org 70 i Err bitreich.org 70 i- if (fstat(fd, &st) >= 0) Err bitreich.org 70 i+ /* Err bitreich.org 70 i+ * The story of xsendfile. Err bitreich.org 70 i+ * Err bitreich.org 70 i+ * Once upon a time, here you saw a big #ifdef switch source of Err bitreich.org 70 i+ * many ways how to send files with special functions on Err bitreich.org 70 i+ * different operating systems. All of this was removed, because Err bitreich.org 70 i+ * operating systems and kernels got better over time, Err bitreich.org 70 i+ * simplifying what you need and reducing corner cases. Err bitreich.org 70 i+ * Err bitreich.org 70 i+ * For example Linux sendfile(2) sounds nice and faster, but Err bitreich.org 70 i+ * the function is different on every OS and slower to the now Err bitreich.org 70 i+ * used approach of read(2) and write(2). Err bitreich.org 70 i+ * Err bitreich.org 70 i+ * If you ever consider changing this to some "faster" approach, Err bitreich.org 70 i+ * consider benchmarks on all platforms. Err bitreich.org 70 i+ */ Err bitreich.org 70 i+ Err bitreich.org 70 i+ if (fstat(fd, &st) >= 0) { Err bitreich.org 70 i if ((bufsiz = st.st_blksize) < BUFSIZ) Err bitreich.org 70 i bufsiz = BUFSIZ; Err bitreich.org 70 i+ } Err bitreich.org 70 i Err bitreich.org 70 i sendb = xmalloc(bufsiz); Err bitreich.org 70 i while ((len = read(fd, sendb, bufsiz)) > 0) { Err bitreich.org 70 i@@ -133,6 +151,7 @@ xsendfile(int fd, int sock) Err bitreich.org 70 i } Err bitreich.org 70 i } Err bitreich.org 70 i free(sendb); Err bitreich.org 70 i+ Err bitreich.org 70 i return 0; Err bitreich.org 70 i } Err bitreich.org 70 i Err bitreich.org 70 .