Introduction
Introduction Statistics Contact Development Disclaimer Help
Simplify the timeout logic. Make comments more clear. - geomyidae - A small C-b…
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit f6d49dbdcefb8ff41d19939401efe8d11054e592
parent c8c0cd126424dfd23ff7df6d60f32e1bb18deff6
Author: Christoph Lohmann <[email protected]>
Date: Sun, 18 Feb 2018 11:23:48 +0100
Simplify the timeout logic. Make comments more clear.
Diffstat:
M 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);
}
}
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.