diff options
author | Rob Landley <rob@landley.net> | 2019-02-05 08:14:40 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-02-05 08:14:40 -0600 |
commit | 11b2780ea60acd359bda7923e5d4460b3835f053 (patch) | |
tree | 81874846c3bdaada8518f73cc0760422e201ba81 | |
parent | 7a3f339fd722bf9cc13fff1fde7bd98bfed9f67f (diff) | |
download | toybox-11b2780ea60acd359bda7923e5d4460b3835f053.tar.gz |
Fix server loop timeout logic.
-rw-r--r-- | toys/pending/sntp.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/toys/pending/sntp.c b/toys/pending/sntp.c index bd2f75ca..8a061584 100644 --- a/toys/pending/sntp.c +++ b/toys/pending/sntp.c @@ -148,32 +148,31 @@ void sntp_main(void) // loop sending/receiving packets for (;;) { + now = millitime(); + // Figure out if we're in server and multicast modes don't poll if (FLAG(m) || FLAG(S)) then = -1; // daemon and oneshot modes send a packet each time through outer loop else { - then = (now = millitime()) + 3000; - + then = now + 3000; if (FLAG(d) || FLAG(D)) then = now + (1<<TT.r)*1000; - // Prepare outgoing NTP packet + // Send NTP query packet memset(toybuf, 0, 48); *toybuf = 0xe3; // li = 3 (unsynchronized), version = 4, mode = 3 (client) toybuf[2] = 8; // poll frequency 1<<8 = 256 seconds pktime[5] = SWAP_BE64(before = lunchtime(&tv, diff)); - - // Send packet xsendto(fd, toybuf, 48, ai->ai_addr); } // Loop receiving packets until it's time to send the next one. - while (then>0 && now<then) { + for (;;) { int strike; // Wait to receive a packet - now = millitime(); + if (then>0 && then<(now = millitime())) break;; strike = xrecvwait(fd, toybuf, sizeof(toybuf), &sa, then-now); if (strike<1) { if (!(FLAG(S)||FLAG(m)||FLAG(D)||FLAG(d)) && ++tries == 3) |