code: drawterm

Download patch

ref: a8472c1d56c5663f7c4c97e172da84bbc6959cdd
parent: fd1a984ff0bbd2cf91adad5adfa1f61f2cd1ad93
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Jan 6 15:07:46 EST 2018

aan: implement client timeout

--- a/aan.c
+++ b/aan.c
@@ -30,6 +30,7 @@
 	char	*addr;
 	int	netfd;
 	int	pipefd;
+	int	timeout;
 
 	int	reader;
 	int	writer;
@@ -47,8 +48,10 @@
 {
 	Buf *b;
 	int n;
+	ulong to;
 
 	qlock(&c->lk);
+	to = (ulong)time(0) + c->timeout;
 Again:
 	for(;;){
 		if(c->netfd >= 0){
@@ -56,7 +59,9 @@
 			c->netfd = -1;
 		}
 		if((c->netfd = dial(c->addr,nil,nil,nil)) >= 0)
-			break;
+			break;		
+		if((ulong)time(0) >= to)
+			sysfatal("dial timed out: %r");
 		sleep(1000);
 	}
 	for(b = c->unackedhead; b != nil; b = b->next){
@@ -189,7 +194,7 @@
 }
 
 int
-aanclient(char *addr)
+aanclient(char *addr, int timeout)
 {
 	Client *c;
 	int pfd[2];
@@ -203,7 +208,9 @@
 	c->pipefd = pfd[1];
 	c->inmsg = 0;
 	c->outmsg = 0;
+	c->timeout = 60;
 	reconnect(c);
+	c->timeout = timeout;
 	c->writer = kproc("aanwriter", aanwriter, c);
 	c->reader = kproc("aanreader", aanreader, c);
 	c->syncer = kproc("aansyncer", aansyncer, c);
--- a/cpu.c
+++ b/cpu.c
@@ -115,7 +115,7 @@
 	else
 		na = strdup(buf);
 
-	return aanclient(na);
+	return aanclient(na, aanto);
 }
 
 void
--- a/drawterm.h
+++ b/drawterm.h
@@ -7,5 +7,5 @@
 extern char *getuser(void);
 extern void cpumain(int, char**);
 extern char *estrdup(char*);
-extern int aanclient(char*);
+extern int aanclient(char*, int);