make hwrite work with chunked encoding

This commit is contained in:
rsc 2005-02-16 17:13:41 +00:00
parent 80b8842f3e
commit 7eded25c3c

View file

@ -443,7 +443,7 @@ hlflush(Hio* h)
int int
hwrite(Hio *h, void *vbuf, int len) hwrite(Hio *h, void *vbuf, int len)
{ {
uchar *pos, *buf; uchar *buf;
int n, m; int n, m;
buf = vbuf; buf = vbuf;
@ -453,36 +453,30 @@ hwrite(Hio *h, void *vbuf, int len)
h->stop = h->pos; h->stop = h->pos;
return -1; return -1;
} }
pos = h->pos; if(h->pos + n >= h->stop){
if(pos + n >= h->stop){ if(h->start != h->pos)
m = pos - h->start; if(hflush(h) < 0)
if(m){ return -1;
m = Hsize - m; while(h->pos + n >= h->stop){
if(m){ m = h->stop - h->pos;
memmove(pos, buf, m); 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;
}
n -= m;
buf += m; buf += m;
n -= m;
} }
if(write(h->fd, h->start, Hsize) != Hsize){
h->state = Herr;
h->stop = h->pos;
return -1;
} }
h->seek += Hsize; memmove(h->pos, buf, n);
} h->pos += n;
m = n % Hsize;
n -= m;
if(n != 0 && write(h->fd, buf, n) != n){
h->state = Herr;
h->stop = h->pos;
return -1;
}
h->seek += n;
buf += n;
pos = h->pos = h->start;
n = m;
}
memmove(pos, buf, n);
h->pos = pos + n;
return len; return len;
} }