summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp/main.c
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>1998-06-24 19:33:36 +0000
committerbrian <brian@FreeBSD.org>1998-06-24 19:33:36 +0000
commit7c567ca3f8ef3ab5a1e088fbf86a9b1cd2e6718e (patch)
treecb27c2021e7933ab6a8a0c8a33e27883241617a8 /usr.sbin/ppp/main.c
parentbe4ceaedbf3a7a77628a0d38a412cd66fbcab341 (diff)
downloadFreeBSD-src-7c567ca3f8ef3ab5a1e088fbf86a9b1cd2e6718e.zip
FreeBSD-src-7c567ca3f8ef3ab5a1e088fbf86a9b1cd2e6718e.tar.gz
o If we come out of select() with only write descriptors that
end up writing zero bytes, sleep for 1/10 of a second so that we don't end up using up too much cpu. This should only ever happen on systems that wrongly report a descriptor as writable despite the tty buffer being full. Discussed with: Jeff Evarts o Do an initial run-time check to see if select() alters the passed timeval. This knowledge isn't yet used, but will be soon.
Diffstat (limited to 'usr.sbin/ppp/main.c')
-rw-r--r--usr.sbin/ppp/main.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index ab0be06..372fa67 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.134 1998/06/16 19:40:27 brian Exp $
+ * $Id: main.c,v 1.135 1998/06/16 19:40:39 brian Exp $
*
* TODO:
*/
@@ -40,6 +40,7 @@
#include <termios.h>
#include <unistd.h>
+#include "probe.h"
#include "mbuf.h"
#include "log.h"
#include "defs.h"
@@ -442,7 +443,10 @@ static void
DoLoop(struct bundle *bundle)
{
fd_set rfds, wfds, efds;
- int i, nfds;
+ int i, nfds, nothing_done;
+ struct probe probe;
+
+ probe_Init(&probe);
do {
nfds = 0;
@@ -514,14 +518,32 @@ DoLoop(struct bundle *bundle)
if (i <= nfds)
break;
- if (descriptor_IsSet(&server.desc, &rfds))
+ nothing_done = 1;
+
+ if (descriptor_IsSet(&server.desc, &rfds)) {
descriptor_Read(&server.desc, bundle, &rfds);
+ nothing_done = 0;
+ }
+
+ if (descriptor_IsSet(&bundle->desc, &rfds)) {
+ descriptor_Read(&bundle->desc, bundle, &rfds);
+ nothing_done = 0;
+ }
if (descriptor_IsSet(&bundle->desc, &wfds))
- descriptor_Write(&bundle->desc, bundle, &wfds);
+ if (!descriptor_Write(&bundle->desc, bundle, &wfds) && nothing_done) {
+ /*
+ * This is disasterous. The OS has told us that something is
+ * writable, and all our write()s have failed. Rather than
+ * going back immediately to do our UpdateSet()s and select(),
+ * we sleep for a bit to avoid gobbling up all cpu time.
+ */
+ struct timeval t;
- if (descriptor_IsSet(&bundle->desc, &rfds))
- descriptor_Read(&bundle->desc, bundle, &rfds);
+ t.tv_sec = 0;
+ t.tv_usec = 100000;
+ select(0, NULL, NULL, NULL, &t);
+ }
} while (bundle_CleanDatalinks(bundle), !bundle_IsDead(bundle));
OpenPOWER on IntegriCloud