shithub: 9pro

Download patch

ref: f699d4388171aed340cd1154766a473bac6f97c6
parent: 21894b798a130c1fe06b1059ef3122df75c6e6d7
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed May 20 09:03:11 EDT 2020

9gc: do a dummy read each 10 second of inactivity, hoping for Android to not close the socket

--- a/9gc.c
+++ b/9gc.c
@@ -322,6 +322,7 @@
 static int
 chatrw(C9aux *a)
 {
+	struct timeval t;
 	fd_set r, e;
 	int n, sz;
 	C9tag tag;
@@ -334,9 +335,11 @@
 	FD_ZERO(&e);
 	FD_SET(a->f, &e);
 	FD_SET(0, &e);
+	memset(&t, 0, sizeof(t));
+	t.tv_sec = 10;
 	for (;;) {
 		errno = 0;
-		if ((n = select(a->f + 1, &r, NULL, &e, NULL)) < 0 || FD_ISSET(a->f, &e) || FD_ISSET(0, &e)) {
+		if ((n = select(a->f + 1, &r, NULL, &e, &t)) < 0 || FD_ISSET(a->f, &e) || FD_ISSET(0, &e)) {
 			if (errno == EINTR)
 				continue;
 			return -1;
@@ -345,9 +348,9 @@
 	}
 
 	ctx = (C9ctx*)a;
-	if (FD_ISSET(a->f, &r))
+	if (FD_ISSET(a->f, &r)) {
 		c9proc(ctx);
-	if (FD_ISSET(0, &r)) {
+	} else if (FD_ISSET(0, &r)) {
 		s = (char*)a->rdbuf;
 		sz = sprintf(s, "%s → ", nick);
 		for (;;) {
@@ -362,6 +365,8 @@
 				break;
 			}
 		}
+	} else {
+		c9read(ctx, &tag, Chatfid, 0, 0);
 	}
 
 	return 0;