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.
This commit is contained in:
parent
1fcddf2eea
commit
1af29a6e96
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=37141
@ -1,11 +1,11 @@
|
||||
# $Id: Makefile,v 1.40 1998/06/07 17:08:42 brian Exp $
|
||||
# $Id: Makefile,v 1.41 1998/06/09 05:36:37 imp Exp $
|
||||
|
||||
PROG= ppp
|
||||
SRCS= arp.c async.c auth.c bundle.c ccp.c chap.c chat.c command.c \
|
||||
datalink.c deflate.c defs.c filter.c fsm.c hdlc.c id.c ip.c \
|
||||
ipcp.c iplist.c lcp.c link.c log.c lqr.c main.c mbuf.c modem.c \
|
||||
mp.c pap.c physical.c pred.c prompt.c route.c server.c sig.c \
|
||||
slcompress.c systems.c throughput.c timer.c tun.c vjcomp.c
|
||||
mp.c pap.c physical.c pred.c probe.c prompt.c route.c server.c \
|
||||
sig.c slcompress.c systems.c throughput.c timer.c tun.c vjcomp.c
|
||||
CFLAGS+=-Wall
|
||||
LDADD+= -lutil -lz
|
||||
DPADD+= ${LIBUTIL} ${LIBZ}
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: bundle.c,v 1.21 1998/06/20 00:19:32 brian Exp $
|
||||
* $Id: bundle.c,v 1.22 1998/06/20 01:36:38 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -679,11 +679,12 @@ bundle_DescriptorRead(struct descriptor *d, struct bundle *bundle,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
bundle_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
|
||||
const fd_set *fdset)
|
||||
{
|
||||
struct datalink *dl;
|
||||
int result = 0;
|
||||
|
||||
/* This is not actually necessary as struct mpserver doesn't Write() */
|
||||
if (descriptor_IsSet(&bundle->ncp.mp.server.desc, fdset))
|
||||
@ -691,7 +692,9 @@ bundle_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
|
||||
|
||||
for (dl = bundle->links; dl; dl = dl->next)
|
||||
if (descriptor_IsSet(&dl->desc, fdset))
|
||||
descriptor_Write(&dl->desc, bundle, fdset);
|
||||
result += descriptor_Write(&dl->desc, bundle, fdset);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: chat.c,v 1.47 1998/05/28 23:17:38 brian Exp $
|
||||
* $Id: chat.c,v 1.48 1998/06/15 19:06:38 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -464,10 +464,11 @@ chat_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
chat_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
{
|
||||
struct chat *c = descriptor2chat(d);
|
||||
int result = 0;
|
||||
|
||||
if (c->state == CHAT_SEND) {
|
||||
int wrote;
|
||||
@ -491,6 +492,7 @@ chat_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
}
|
||||
|
||||
wrote = physical_Write(c->physical, c->argptr, c->arglen);
|
||||
result = wrote ? 1 : 0;
|
||||
if (wrote == -1) {
|
||||
if (errno != EINTR)
|
||||
log_Printf(LogERROR, "chat_Write: %s\n", strerror(errno));
|
||||
@ -507,6 +509,8 @@ chat_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
c->arglen -= wrote;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: datalink.c,v 1.10 1998/06/16 07:15:16 brian Exp $
|
||||
* $Id: datalink.c,v 1.11 1998/06/20 00:19:35 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -363,10 +363,11 @@ datalink_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
datalink_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
{
|
||||
struct datalink *dl = descriptor2datalink(d);
|
||||
int result = 0;
|
||||
|
||||
switch (dl->state) {
|
||||
case DATALINK_CLOSED:
|
||||
@ -376,16 +377,18 @@ datalink_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
case DATALINK_HANGUP:
|
||||
case DATALINK_DIAL:
|
||||
case DATALINK_LOGIN:
|
||||
descriptor_Write(&dl->chat.desc, bundle, fdset);
|
||||
result = descriptor_Write(&dl->chat.desc, bundle, fdset);
|
||||
break;
|
||||
|
||||
case DATALINK_READY:
|
||||
case DATALINK_LCP:
|
||||
case DATALINK_AUTH:
|
||||
case DATALINK_OPEN:
|
||||
descriptor_Write(&dl->physical->desc, bundle, fdset);
|
||||
result = descriptor_Write(&dl->physical->desc, bundle, fdset);
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: descriptor.h,v 1.2 1998/05/21 21:45:08 brian Exp $
|
||||
* $Id: descriptor.h,v 1.3 1998/05/23 22:24:34 brian Exp $
|
||||
*/
|
||||
|
||||
#define PHYSICAL_DESCRIPTOR (1)
|
||||
@ -42,7 +42,7 @@ struct descriptor {
|
||||
int (*UpdateSet)(struct descriptor *, fd_set *, fd_set *, fd_set *, int *);
|
||||
int (*IsSet)(struct descriptor *, const fd_set *);
|
||||
void (*Read)(struct descriptor *, struct bundle *, const fd_set *);
|
||||
void (*Write)(struct descriptor *, struct bundle *, const fd_set *);
|
||||
int (*Write)(struct descriptor *, struct bundle *, const fd_set *);
|
||||
};
|
||||
|
||||
#define descriptor_UpdateSet(d, r, w, e, n) ((*(d)->UpdateSet)(d, r, w, e, n))
|
||||
|
@ -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));
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* $Id: modem.c,v 1.91 1998/06/16 19:40:39 brian Exp $
|
||||
* $Id: modem.c,v 1.92 1998/06/18 22:43:18 brian Exp $
|
||||
*
|
||||
* TODO:
|
||||
*/
|
||||
@ -78,8 +78,8 @@
|
||||
#include "systems.h"
|
||||
|
||||
|
||||
static void modem_DescriptorWrite(struct descriptor *, struct bundle *,
|
||||
const fd_set *);
|
||||
static int modem_DescriptorWrite(struct descriptor *, struct bundle *,
|
||||
const fd_set *);
|
||||
static void modem_DescriptorRead(struct descriptor *, struct bundle *,
|
||||
const fd_set *);
|
||||
static int modem_UpdateSet(struct descriptor *, fd_set *, fd_set *, fd_set *,
|
||||
@ -831,12 +831,12 @@ modem_LogicalClose(struct physical *modem)
|
||||
modem->name.base = modem->name.full;
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
modem_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
|
||||
const fd_set *fdset)
|
||||
{
|
||||
struct physical *modem = descriptor2physical(d);
|
||||
int nb, nw;
|
||||
int nb, nw, result = 0;
|
||||
|
||||
if (modem->out == NULL)
|
||||
modem->out = link_Dequeue(&modem->link);
|
||||
@ -851,14 +851,19 @@ modem_DescriptorWrite(struct descriptor *d, struct bundle *bundle,
|
||||
modem->out->offset += nw;
|
||||
if (modem->out->cnt == 0)
|
||||
modem->out = mbuf_FreeSeg(modem->out);
|
||||
result = 1;
|
||||
} else if (nw < 0) {
|
||||
if (errno != EAGAIN) {
|
||||
log_Printf(LogPHASE, "%s: write (%d): %s\n", modem->link.name,
|
||||
modem->fd, strerror(errno));
|
||||
datalink_Down(modem->dl, CLOSE_NORMAL);
|
||||
}
|
||||
result = 1;
|
||||
}
|
||||
/* else we shouldn't really have been called ! select() is broken ! */
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: mp.c,v 1.9 1998/06/16 19:40:40 brian Exp $
|
||||
* $Id: mp.c,v 1.10 1998/06/20 00:19:42 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -901,11 +901,12 @@ mpserver_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
mpserver_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
{
|
||||
/* We never want to write here ! */
|
||||
log_Printf(LogALERT, "mpserver_Write: Internal error: Bad call !\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: prompt.c,v 1.6 1998/06/16 07:15:11 brian Exp $
|
||||
* $Id: prompt.c,v 1.7 1998/06/16 19:40:40 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -276,11 +276,12 @@ prompt_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
prompt_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
{
|
||||
/* We never want to write here ! */
|
||||
log_Printf(LogALERT, "prompt_Write: Internal error: Bad call !\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct prompt *
|
||||
|
@ -23,7 +23,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: server.c,v 1.19 1998/05/23 22:24:50 brian Exp $
|
||||
* $Id: server.c,v 1.20 1998/06/16 19:40:41 brian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
@ -175,11 +175,12 @@ server_Read(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
descriptor_Read(&p->desc, bundle, fdset);
|
||||
}
|
||||
|
||||
static void
|
||||
static int
|
||||
server_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
|
||||
{
|
||||
/* We never want to write here ! */
|
||||
log_Printf(LogALERT, "server_Write: Internal error: Bad call !\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct server server = {
|
||||
|
Loading…
Reference in New Issue
Block a user