ref: 41372f346ae5636e59284ff698d8202e8301641f
parent: 39c9f1abbb11b310e77f43fe4f5e580f1791be67
author: cinap_lenrek <[email protected]>
date: Mon Jul 13 01:51:04 EDT 2015
httpfile: fix evictblock() so we wont consume all the memory
--- a/sys/src/cmd/ip/httpfile.c
+++ b/sys/src/cmd/ip/httpfile.c
@@ -114,11 +114,11 @@
for(l=&cache->first; (b=*l) != nil; l=&b->link){
if(b->rq != nil) /* dont touch block when still requests queued */
continue;
- if(b->rq != nil && (oldest == nil || (*oldest)->lastuse > b->lastuse))
+ if(oldest == nil || (*oldest)->lastuse > b->lastuse)
oldest = l;
}
- if(oldest == nil)
+ if(oldest == nil || *oldest == nil || (*oldest)->rq != nil)
return;
b = *oldest;
@@ -439,8 +439,7 @@
b = recvp(finishchan);
assert(b == inprogress.first);
inprogress.first = b->link;
- ncache++;
- if(ncache >= mcache)
+ if(++ncache >= mcache)
evictblock(&cache);
addblock(&cache, b);
while((r = b->rq) != nil){
@@ -448,7 +447,7 @@
r->aux = nil;
readfrom(r, b);
}
- if(inprogress.first)
+ if(inprogress.first != nil)
sendp(httpchan, inprogress.first);
}
}