ip/httpfile: fix flushes, fix concurrent reads, set error string

Tflush handling was wrong, we cannot respond to the old
request if we have not actually removed the req from the
in progress block queue.

when reads are issued concurrently, we have to set b->len
before the block is inserted into the inprogress list.
otherwise findblock() is unable to find it and no requests
can be queued on the block. this caused the same offset
to be downloaded multiple times.

set the errstr in getrange() so in case of an error, we dont
get some random previous error string.
This commit is contained in:
cinap_lenrek 2015-07-23 03:24:39 +02:00
parent 497daed116
commit ab4b7c2573

View file

@ -100,6 +100,8 @@ delreq(Block *b, Req *r)
*l = r->aux; *l = r->aux;
if(*l == nil) if(*l == nil)
b->erq = l; b->erq = l;
r->aux = nil;
respond(r, "interrupted");
return; return;
} }
} }
@ -205,10 +207,6 @@ getrange(Block *b)
int fd, cfd; int fd, cfd;
uchar *data; uchar *data;
b->len = Blocksize;
if(b->off + b->len > size)
b->len = size - b->off;
if(debug) if(debug)
print("getrange: %lld %lld\n", b->off, b->len); print("getrange: %lld %lld\n", b->off, b->len);
@ -230,6 +228,8 @@ getrange(Block *b)
close(fd); close(fd);
return nil; return nil;
} }
werrstr("bad contentrange header");
if(readstring(cfd, buf, sizeof(buf)) <= 0){ if(readstring(cfd, buf, sizeof(buf)) <= 0){
Badrange: Badrange:
close(cfd); close(cfd);
@ -244,6 +244,7 @@ Badrange:
/* read body data */ /* read body data */
data = emalloc9p(b->len); data = emalloc9p(b->len);
werrstr("body data truncated");
if(readfile(fd, (char*)data, b->len) != b->len){ if(readfile(fd, (char*)data, b->len) != b->len){
close(fd); close(fd);
free(data); free(data);
@ -410,6 +411,9 @@ fileread(Req *r)
if((b = findblock(&inprogress, r->ifcall.offset)) == nil){ if((b = findblock(&inprogress, r->ifcall.offset)) == nil){
b = emalloc9p(sizeof(Block)); b = emalloc9p(sizeof(Block));
b->off = r->ifcall.offset - (r->ifcall.offset % Blocksize); b->off = r->ifcall.offset - (r->ifcall.offset % Blocksize);
b->len = Blocksize;
if(b->off + b->len > size)
b->len = size - b->off;
addblock(&inprogress, b); addblock(&inprogress, b);
if(inprogress.first == b) if(inprogress.first == b)
sendp(httpchan, b); sendp(httpchan, b);
@ -467,10 +471,11 @@ fsnetproc(void*)
switch(r->ifcall.type){ switch(r->ifcall.type){
case Tflush: case Tflush:
o = r->oldreq; o = r->oldreq;
b = findblock(&inprogress, o->ifcall.offset); if(o->ifcall.type == Tread){
if(b != nil) b = findblock(&inprogress, o->ifcall.offset);
delreq(b, o); if(b != nil)
respond(o, "interrupted"); delreq(b, o);
}
respond(r, nil); respond(r, nil);
break; break;
case Tread: case Tread: