diff options
author | brian <brian@FreeBSD.org> | 1999-03-30 00:44:57 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1999-03-30 00:44:57 +0000 |
commit | e9c44757c375afcb9faf84f23607abb1a92494e5 (patch) | |
tree | aa9b7363acb539fc8b70775c99982dae645d6344 /usr.sbin | |
parent | 6b64c5f82731e7fdc2065707f878a7e75ed76152 (diff) | |
download | FreeBSD-src-e9c44757c375afcb9faf84f23607abb1a92494e5.zip FreeBSD-src-e9c44757c375afcb9faf84f23607abb1a92494e5.tar.gz |
Maintain a `necessary' marker to indicate that we *probably*
need to process a signal (usually a SIGALRM). Check to see
if we need to process a signal both before *and* after calling
select() as older (pre-2.0) versions of ppp used to.
This handles the possibility that ppp may block at some
point (maybe due to an open() of a misconfigured device).
Previously, we'd potentially lock up in select().
The `necessary' marker reduces the increased signal checking
overhead so that at full speed with no compression transferring
an 83Mb file via a ``!ppp -direct'' device, we get a 1%
throughput gain.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/main.c | 13 | ||||
-rw-r--r-- | usr.sbin/ppp/sig.c | 34 | ||||
-rw-r--r-- | usr.sbin/ppp/sig.h | 4 |
3 files changed, 37 insertions, 14 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index 958a16d..4eb99d4 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.150 1999/02/06 02:54:46 brian Exp $ + * $Id: main.c,v 1.151 1999/03/07 01:02:38 brian Exp $ * * TODO: */ @@ -474,6 +474,17 @@ DoLoop(struct bundle *bundle) /* Don't select - we'll be here forever */ break; + /* + * It's possible that we've had a signal since we last checked. If + * we don't check again before calling select(), we may end up stuck + * after having missed the event.... sig_Handle() tries to be as + * quick as possible if nothing is likely to have happened. + * This is only really likely if we block in open(... O_NONBLOCK) + * which will happen with a misconfigured device. + */ + if (sig_Handle()) + continue; + i = select(nfds, &rfds, &wfds, &efds, NULL); if (i < 0 && errno != EINTR) { diff --git a/usr.sbin/ppp/sig.c b/usr.sbin/ppp/sig.c index b79e7e9..1a771ae 100644 --- a/usr.sbin/ppp/sig.c +++ b/usr.sbin/ppp/sig.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: sig.c,v 1.11.2.5 1998/05/01 19:25:56 brian Exp $ + * $Id: sig.c,v 1.13 1998/05/21 21:48:20 brian Exp $ */ #include <sys/types.h> @@ -34,6 +34,7 @@ #include "sig.h" static int caused[NSIG]; /* An array of pending signals */ +static int necessary; /* Anything set ? */ static sig_type handler[NSIG]; /* all start at SIG_DFL */ @@ -43,6 +44,7 @@ static void signal_recorder(int sig) { caused[sig - 1]++; + necessary = 1; } @@ -77,19 +79,29 @@ sig_signal(int sig, sig_type fn) /* Call the handlers for any pending signals */ -void +int sig_Handle() { int sig; int got; + int result; - do { - got = 0; - for (sig = 0; sig < NSIG; sig++) - if (caused[sig]) { - caused[sig]--; - got++; - (*handler[sig]) (sig + 1); - } - } while (got); + result = 0; + if (necessary) { + /* We've *probably* got something in `caused' set */ + necessary = 0; + /* `necessary' might go back to 1 while we're in here.... */ + do { + got = 0; + for (sig = 0; sig < NSIG; sig++) + if (caused[sig]) { + caused[sig]--; + got++; + result++; + (*handler[sig])(sig + 1); + } + } while (got); + } + + return result; } diff --git a/usr.sbin/ppp/sig.h b/usr.sbin/ppp/sig.h index 5b0a4f0..ed49509 100644 --- a/usr.sbin/ppp/sig.h +++ b/usr.sbin/ppp/sig.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: sig.h,v 1.11.2.1 1998/05/01 19:25:57 brian Exp $ + * $Id: sig.h,v 1.12 1998/05/21 21:48:23 brian Exp $ */ typedef void (*sig_type)(int); @@ -32,4 +32,4 @@ typedef void (*sig_type)(int); extern sig_type sig_signal(int, sig_type); /* Call this when you want things to *actually* happen */ -extern void sig_Handle(void); +extern int sig_Handle(void); |