git: 9front

Download patch

ref: 460e03c222136f08d004ba2494ae464f6982a320
parent: b8fc964979583fc7968317ca3cda951fd5e79baa
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sat Mar 31 22:09:57 EDT 2012

webfs: keep up to 4 connections per peer in pool

--- a/sys/src/cmd/webfs/http.c
+++ b/sys/src/cmd/webfs/http.c
@@ -37,6 +37,7 @@
 	int	active;
 
 	int	limit;
+	int	peer;
 	int	idle;
 };
 
@@ -49,6 +50,7 @@
 
 static Hpool hpool = {
 	.limit	= 16,
+	.peer	= 4,
 	.idle	= 5,	/* seconds */
 };
 
@@ -128,7 +130,7 @@
 hclose(Hconn *h)
 {
 	Hconn *x, *t;
-	int i;
+	int i, n;
 
 	if(h == nil)
 		return;
@@ -135,9 +137,10 @@
 
 	qlock(&hpool);
 	if(h->keep && h->fd >= 0){
-		for(i = 0, t = nil, x = hpool.head; x; x = x->next){
+		for(n = 0, i = 0, t = nil, x = hpool.head; x; x = x->next){
 			if(strcmp(x->addr, h->addr) == 0)
-				break;
+				if(++n > hpool.peer)
+					break;
 			if(++i < hpool.limit)
 				t = x;
 		}
--