shithub: riscv

Download patch

ref: 4c16111e66763cf0b427082c4132b53e050d4ba2
parent: 595f9c4a09bedffab4d7f6dc95c7c7c2720412cb
author: cinap_lenrek <[email protected]>
date: Wed May 16 13:00:19 EDT 2012

webfs: add global timeout parameter settable in rootctl and command line

--- a/sys/man/4/webfs
+++ b/sys/man/4/webfs
@@ -4,6 +4,12 @@
 .SH SYNOPSIS
 .B webfs
 [
+.B -A
+.I useragent
+] [
+.B -T
+.I timeout
+] [
 .B -m
 .I mtpt
 ]
@@ -131,7 +137,7 @@
 as it arrives.
 .PP
 The following is a list of attributes that can be
-set to to a connection prior initiating the request:
+set to do a connection prior initiating the request:
 .TP
 .B url,baseurl
 See above.
--- a/sys/src/cmd/webfs/dat.h
+++ b/sys/src/cmd/webfs/dat.h
@@ -65,3 +65,4 @@
 
 int	debug;
 Url	*proxy;
+int	timeout;
--- a/sys/src/cmd/webfs/fs.c
+++ b/sys/src/cmd/webfs/fs.c
@@ -506,7 +506,7 @@
 		respond(r, nil);
 		return;
 	case Qrctl:
-		buf[0] = 0;
+		snprint(buf, sizeof(buf), "useragent %s\ntimeout %d\n", agent, timeout);
 	String:
 		readstr(r, buf);
 		respond(r, nil);
@@ -561,6 +561,16 @@
 		return nil;
 	}
 
+	if(!strcmp(ctl, "timeout")){
+		if(arg && *arg)
+			timeout = atoi(arg);
+		else
+			timeout = 0;
+		if(timeout < 0)
+			timeout = 0;
+		return nil;
+	}
+
 	return "bad ctl message";
 }
 
@@ -714,7 +724,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-D] [-m mtpt] [-s srv]\n", argv0);
+	fprint(2, "usage: %s [-D] [-A useragent] [-T timeout] [-m mtpt] [-s srv]\n", argv0);
 	exits("usage");
 }
 
@@ -731,11 +741,21 @@
 	mtpt = "/mnt/web";
 	user = getuser();
 	time0 = time(0);
+	timeout = 10000;
+	agent = nil;
 
 	ARGBEGIN {
 	case 'D':
 		chatty9p++;
 		break;
+	case 'A':
+		agent = EARGF(usage());
+		break;
+	case 'T':
+		timeout = atoi(EARGF(usage()));
+		if(timeout < 0)
+			timeout = 0;
+		break;
 	case 'm':
 		mtpt = EARGF(usage());
 		break;
@@ -751,7 +771,10 @@
 
 	rfork(RFNOTEG);
 
-	agent = estrdup("hjdicks");
+	if(agent == nil)
+		agent = "hjdicks";
+	agent = estrdup(agent);
+
 	if(s = getenv("httpproxy")){
 		proxy = saneurl(url(s, 0));
 		free(s);
--- a/sys/src/cmd/webfs/http.c
+++ b/sys/src/cmd/webfs/http.c
@@ -542,9 +542,8 @@
 			qunlock(qpost);
 		}
 
-		/* give 10 seconds to dial */
 		if(h == nil){
-			alarm(10000);
+			alarm(timeout);
 			if((h = hdial(proxy ? proxy : u)) == nil)
 				break;
 		}
@@ -619,10 +618,8 @@
 			}
 			/* no timeout when posting */
 			alarm(0);
-		} else {
-			/* wait 20 seconds for the response */
-			alarm(20000);
-		}
+		} else
+			alarm(timeout);
 
 		Cont:
 		rhdr = 0;