diff options
-rw-r--r-- | usr.sbin/ppp/main.c | 13 | ||||
-rw-r--r-- | usr.sbin/ppp/timer.c | 82 | ||||
-rw-r--r-- | usr.sbin/ppp/timer.h | 4 |
3 files changed, 46 insertions, 53 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 4a9c677..2e303f6 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.112 1997/12/27 13:45:53 brian Exp $ + * $Id: main.c,v 1.113 1997/12/28 02:46:26 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -915,16 +915,15 @@ DoLoop(void) FD_SET(server, &rfds); } +#ifndef SIGALRM /* * *** IMPORTANT *** - * * CPU is serviced every TICKUNIT micro seconds. This value must be chosen - * with great care. If this values is too big, it results loss of - * characters from modem and poor responce. If this values is too small, - * ppp process eats many CPU time. + * with great care. If this values is too big, it results in loss of + * characters from the modem and poor response. If this value is too + * small, ppp eats too much CPU time. */ -#ifndef SIGALRM - nointr_usleep(TICKUNIT); + usleep(TICKUNIT); TimerService(); #else handle_signals(); diff --git a/usr.sbin/ppp/timer.c b/usr.sbin/ppp/timer.c index 7cd449d..7a252a2 100644 --- a/usr.sbin/ppp/timer.c +++ b/usr.sbin/ppp/timer.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: timer.c,v 1.23 1997/11/09 06:22:49 brian Exp $ + * $Id: timer.c,v 1.24 1997/11/22 03:37:52 brian Exp $ * * TODO: */ @@ -207,66 +207,60 @@ ShowTimers() } #ifdef SIGALRM -u_int -nointr_sleep(u_int sec) + +static void +nointr_dosleep(u_int sec, u_int usec) { struct timeval to, st, et; - long sld, nwd, std; gettimeofday(&st, NULL); + et.tv_sec = st.tv_sec + sec; + et.tv_usec = st.tv_usec + usec; to.tv_sec = sec; - to.tv_usec = 0; - std = st.tv_sec * 1000000 + st.tv_usec; + to.tv_usec = usec; for (;;) { if (select(0, NULL, NULL, NULL, &to) == 0 || errno != EINTR) { break; } else { - gettimeofday(&et, NULL); - sld = to.tv_sec * 1000000 + to.tv_sec; - nwd = et.tv_sec * 1000000 + et.tv_usec - std; - if (sld > nwd) - sld -= nwd; - else - sld = 1; /* Avoid both tv_sec/usec is 0 */ - - /* Calculate timeout value for select */ - to.tv_sec = sld / 1000000; - to.tv_usec = sld % 1000000; + gettimeofday(&to, NULL); + if (to.tv_sec > et.tv_sec || + (to.tv_sec == et.tv_sec && to.tv_usec > et.tv_usec) || + to.tv_sec < st.tv_sec || + (to.tv_sec == st.tv_sec && to.tv_usec < st.tv_usec)) { + LogPrintf(LogWARN, "Clock adjusted between %d and %d seconds " + "during sleep !\n", + to.tv_sec - st.tv_sec, sec + to.tv_sec - st.tv_sec); + st.tv_sec = to.tv_sec; + st.tv_usec = to.tv_usec; + et.tv_sec = st.tv_sec + sec; + et.tv_usec = st.tv_usec + usec; + to.tv_sec = sec; + to.tv_usec = usec; + } else if (to.tv_sec == et.tv_sec && to.tv_usec == et.tv_usec) { + break; + } else { + to.tv_sec = et.tv_sec - to.tv_sec; + if (et.tv_usec < to.tv_usec) { + to.tv_sec--; + to.tv_usec = 1000000 + et.tv_usec - to.tv_usec; + } else + to.tv_usec = et.tv_usec - to.tv_usec; + } } } - return (0L); } void -nointr_usleep(u_int usec) +nointr_sleep(u_int sec) { - struct timeval to, st, et; - long sld, nwd, std; - - gettimeofday(&st, NULL); - to.tv_sec = 0; - to.tv_usec = usec; - std = st.tv_sec * 1000000 + st.tv_usec; - for (;;) { - if (select(0, NULL, NULL, NULL, &to) == 0 || - errno != EINTR) { - break; - } else { - gettimeofday(&et, NULL); - sld = to.tv_sec * 1000000 + to.tv_sec; - nwd = et.tv_sec * 1000000 + et.tv_usec - std; - if (sld > nwd) - sld -= nwd; - else - sld = 1; /* Avoid both tv_sec/usec is 0 */ - - /* Calculate timeout value for select */ - to.tv_sec = sld / 1000000; - to.tv_usec = sld % 1000000; + nointr_dosleep(sec, 0); +} - } - } +void +nointr_usleep(u_int usec) +{ + nointr_dosleep(0, usec); } static void diff --git a/usr.sbin/ppp/timer.h b/usr.sbin/ppp/timer.h index 51d614d..ca9bba2 100644 --- a/usr.sbin/ppp/timer.h +++ b/usr.sbin/ppp/timer.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: timer.h,v 1.2 1997/10/26 12:42:13 brian Exp $ + * $Id: timer.h,v 1.3 1997/11/22 03:37:52 brian Exp $ * * TODO: */ @@ -46,6 +46,6 @@ extern void TermTimerService(void); extern void ShowTimers(void); #ifdef SIGALRM -extern u_int nointr_sleep(u_int); +extern void nointr_sleep(u_int); extern void nointr_usleep(u_int); #endif |