tmake hwrite work with chunked encoding - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 7eded25c3ca4de99069ff4c6f0e44071fe0be079
parent 80b8842f3e4d562e67455de1c1de80cba5532aec
Author: rsc 
Date:   Wed, 16 Feb 2005 17:13:41 +0000

make hwrite work with chunked encoding

Diffstat:
  M src/libhttpd/hio.c                  |      50 ++++++++++++++-----------------

1 file changed, 22 insertions(+), 28 deletions(-)
---
diff --git a/src/libhttpd/hio.c b/src/libhttpd/hio.c
t@@ -443,7 +443,7 @@ hlflush(Hio* h)
 int
 hwrite(Hio *h, void *vbuf, int len)
 {
-        uchar *pos, *buf;
+        uchar *buf;
         int n, m;
 
         buf = vbuf;
t@@ -453,36 +453,30 @@ hwrite(Hio *h, void *vbuf, int len)
                 h->stop = h->pos;
                 return -1;
         }
-        pos = h->pos;
-        if(pos + n >= h->stop){
-                m = pos - h->start;
-                if(m){
-                        m = Hsize - m;
-                        if(m){
-                                memmove(pos, buf, m);
-                                buf += m;
-                                n -= m;
-                        }
-                        if(write(h->fd, h->start, Hsize) != Hsize){
-                                h->state = Herr;
-                                h->stop = h->pos;
+        if(h->pos + n >= h->stop){
+                if(h->start != h->pos)
+                        if(hflush(h) < 0)
                                 return -1;
+                while(h->pos + n >= h->stop){
+                        m = h->stop - h->pos;
+                        if(h->xferenc){
+                                memmove(h->pos, buf, m);
+                                h->pos += m;
+                                if(hflush(h) < 0)
+                                        return -1;
+                        }else{
+                                if(write(h->fd, buf, m) != m){
+                                        h->state = Herr;
+                                        h->stop = h->pos;
+                                        return -1;
+                                }
+                                h->seek += m;
                         }
-                        h->seek += Hsize;
-                }
-                m = n % Hsize;
-                n -= m;
-                if(n != 0 && write(h->fd, buf, n) != n){
-                        h->state = Herr;
-                        h->stop = h->pos;
-                        return -1;
+                        n -= m;
+                        buf += m;
                 }
-                h->seek += n;
-                buf += n;
-                pos = h->pos = h->start;
-                n = m;
         }
-        memmove(pos, buf, n);
-        h->pos = pos + n;
+        memmove(h->pos, buf, n);
+        h->pos += n;
         return len;
 }