# HG changeset patch # User Olaf Wintermann # Date 1667331581 -3600 # Node ID e5d96f6b930680c5d969778eaa68075fc35fc8db # Parent 162f122b96a1b61753e6874f87114d6b13effb95 store number of written bytes in the HttpStream diff -r 162f122b96a1 -r e5d96f6b9306 src/server/util/io.c --- a/src/server/util/io.c Tue Nov 01 16:54:24 2022 +0100 +++ b/src/server/util/io.c Tue Nov 01 20:39:41 2022 +0100 @@ -320,12 +320,17 @@ io[1].iov_len = nbytes; io[2].iov_base = "\r\n"; io[2].iov_len = 2; - // TODO: FIXME: if r < sum of iov_len, everything would explode + // TODO: FIXME: if wv < sum of iov_len, everything would explode // we need to store the chunk state and remaining bytes - ssize_t r = fd->writev(fd, io, 3); - return r - io[0].iov_len - io[2].iov_len; + // TODO: FIX IT NOW, IT IS HORRIBLE BROKEN + ssize_t wv = fd->writev(fd, io, 3); + ssize_t w = wv - io[0].iov_len - io[2].iov_len; + st->written += w > 0 ? w : 0; + return w; } else { - return fd->write(fd, buf, nbytes); + ssize_t w = fd->write(fd, buf, nbytes); + st->written += w > 0 ? w : 0; + return w; } } @@ -349,9 +354,12 @@ ssize_t ret = r - io[0].iov_len; free(io); + st->written += ret; return ret; } else { - return fd->writev(fd, iovec, iovcnt); + ssize_t w = fd->writev(fd, iovec, iovcnt); + st->written += w; + return w; } } diff -r 162f122b96a1 -r e5d96f6b9306 src/server/util/io.h --- a/src/server/util/io.h Tue Nov 01 16:54:24 2022 +0100 +++ b/src/server/util/io.h Tue Nov 01 20:39:41 2022 +0100 @@ -94,6 +94,7 @@ IOStream st; IOStream *fd; + uint64_t written; /* * content-length or current chunk size */