geomyidae

A small C-based gopherd. (gopher://bitreich.org/1/scm/geomyidae)
git clone git://r-36.net/geomyidae
Log | Files | Refs | README | LICENSE

commit f6d49dbdcefb8ff41d19939401efe8d11054e592
parent c8c0cd126424dfd23ff7df6d60f32e1bb18deff6
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun, 18 Feb 2018 11:23:48 +0100

Simplify the timeout logic. Make comments more clear.

Diffstat:
ind.c | 27+++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/ind.c b/ind.c @@ -78,29 +78,32 @@ pendingbytes(int sock) void waitforpendingbytes(int sock) { - int npending, opending, tries; + int npending, opending, trytime; - npending = opending = tries = 0; + npending = opending = 0; + trytime = 10; /* - * Wait until there is nothing pending or the connection stalled for - * 30 seconds. + * Wait until there is nothing pending or the connection stalled + * (nothing was sent) for around 40 seconds. Beware, trytime is + * an exponential wait. */ - while ((npending = pendingbytes(sock)) > 0 && tries < 30000000) { + while ((npending = pendingbytes(sock)) > 0 && trytime < 20000000) { if (opending != 0) { if (opending != npending) { - tries = 0; + trytime = 10; } else { - if (tries == 0) { - tries = 1; - } else { - tries += tries; - } + /* + * Exponentially increase the usleep + * waiting time to not waste CPU + * resources. + */ + trytime += trytime; } } opending = npending; - usleep(tries); + usleep(trytime); } }