store number of written bytes in the HttpStream

Tue, 01 Nov 2022 20:39:41 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 01 Nov 2022 20:39:41 +0100
changeset 406
e5d96f6b9306
parent 405
162f122b96a1
child 407
78af44222463

store number of written bytes in the HttpStream

src/server/util/io.c file | annotate | diff | comparison | revisions
src/server/util/io.h file | annotate | diff | comparison | revisions
--- 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;
     }
 }
 
--- 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
      */

mercurial