Tue, 23 May 2023 18:19:12 +0200
fix net_sendfile not counting number of written bytes
src/server/safs/service.c | file | annotate | diff | comparison | revisions | |
src/server/util/io.c | file | annotate | diff | comparison | revisions |
--- 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;
--- 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; }