# HG changeset patch # User Olaf Wintermann # Date 1684858752 -7200 # Node ID 56cf890dd9ed38e387cfd08e2d55be8fa6f7a624 # Parent 07452a54a22b30800cfc974898d7c5211e8e69b8 fix net_sendfile not counting number of written bytes diff -r 07452a54a22b -r 56cf890dd9ed src/server/safs/service.c --- a/src/server/safs/service.c Mon May 22 10:22:15 2023 +0200 +++ b/src/server/safs/service.c Tue May 23 18:19:12 2023 +0200 @@ -275,6 +275,7 @@ sfd.header = header; sfd.hlen = headerlen; sfd.trailer = NULL; + sfd.tlen = 0; while(remaining > 0) { size_t sflen = remaining < SF_MAX_LEN ? remaining : SF_MAX_LEN; diff -r 07452a54a22b -r 56cf890dd9ed src/server/util/io.c --- a/src/server/util/io.c Mon May 22 10:22:15 2023 +0200 +++ b/src/server/util/io.c Tue May 23 18:19:12 2023 +0200 @@ -144,9 +144,9 @@ trvec.iov_len = sfd->tlen; struct sf_hdtr hdtr; hdtr.headers = &hdvec; - hdtr.hdr_cnt = 1; + hdtr.hdr_cnt = sfd->hlen > 0 ? 1 : 0; hdtr.trailers = &trvec; - hdtr.trl_cnt = 1; + hdtr.trl_cnt = sfd->tlen > 0 ? 1 : 0; off_t len = sfd->len; #ifdef OSX @@ -161,6 +161,10 @@ NULL, 0); #endif + if(ret == 0) { + ret = sfd->hlen + sfd->tlen + sfd->len; + } + #else // Solaris/Linux if(sfd->header) { ret += write(st->fd, sfd->header, sfd->hlen); @@ -610,6 +614,8 @@ ret = net_fallback_sendfile((IOStream*)st, sfd); } + st->written += ret > 0 ? ret : 0; + return ret; }