diff options
author | rsc <devnull@localhost> | 2005-02-16 17:13:41 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-02-16 17:13:41 +0000 |
commit | 7eded25c3ca4de99069ff4c6f0e44071fe0be079 (patch) | |
tree | 24eefda5612f274157426f00494cf106e9c7026f /src/libhttpd | |
parent | 80b8842f3e4d562e67455de1c1de80cba5532aec (diff) | |
download | plan9port-7eded25c3ca4de99069ff4c6f0e44071fe0be079.tar.gz plan9port-7eded25c3ca4de99069ff4c6f0e44071fe0be079.tar.bz2 plan9port-7eded25c3ca4de99069ff4c6f0e44071fe0be079.zip |
make hwrite work with chunked encoding
Diffstat (limited to 'src/libhttpd')
-rw-r--r-- | src/libhttpd/hio.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/src/libhttpd/hio.c b/src/libhttpd/hio.c index 1016ca91..b5339ede 100644 --- a/src/libhttpd/hio.c +++ b/src/libhttpd/hio.c @@ -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; @@ -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; } |