From 92d63375617e9c9b806071ae9ab4bccd24cd017c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Mon, 14 Sep 2020 07:11:24 +0200 Subject: [PATCH] Automatically adjust for SSH lag --- termtest.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/termtest.c b/termtest.c index 27de8fa..90afa73 100644 --- a/termtest.c +++ b/termtest.c @@ -75,10 +75,12 @@ static char *comm(const char *req, bool wait_first) { ssize_t len = write(STDOUT_FILENO, req, strlen(req)); if (len < strlen(req)) return NULL; - char buf[1000] = ""; size_t buf_len = 0; int n = 0; struct pollfd pfd = { .fd = STDIN_FILENO, .events = POLLIN }; if (wait_first) poll(&pfd, 1, -1); - while ((n = poll(&pfd, 1, 50 /* unreliable, timing-dependent */))) { + + int lag = getenv("SSH_CONNECTION") ? 250 : 50; + char buf[1000] = ""; size_t buf_len = 0; int n = 0; + while ((n = poll(&pfd, 1, lag /* unreliable, timing-dependent */))) { if (n < 0) return NULL; len = read(STDIN_FILENO, buf + buf_len, sizeof buf - buf_len - 1); if (len <= 0) return NULL;