From 6dde56a016d502cf422b5c54247e225bb13e26d0 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Wed, 6 May 2009 10:33:49 -0700 Subject: Convert select() arguments back to fd_set structures Signed-off-by: Alan Coopersmith --- fd.c | 33 ++++++++++++++++++++++----------- fd.h | 6 +++--- scope.c | 23 +++++++++++++---------- 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/fd.c b/fd.c index 9c7dffa..af08595 100644 --- a/fd.c +++ b/fd.c @@ -53,6 +53,9 @@ * \* *********************************************************** */ +#include /* for XFD_* macros - must come before + scope.h include to avoid INT32 clash */ + #include "scope.h" #ifdef SYSV @@ -133,7 +136,7 @@ InitializeFD(void) MaxFD -= 4; nFDsInUse = 0 /* stdin, stdout, stderr */ ; - ReadDescriptors = 0; + FD_ZERO(&ReadDescriptors); HighestFD = 0; UsingFD(fileno(stdin), NULL, NULL, NULL); @@ -161,9 +164,9 @@ UsingFD( FDD[fd].trans_conn = trans_conn; #endif if (Handler == NULL) - ReadDescriptors &= ~(1 << fd) /* clear fd bit */ ; + FD_CLR(fd,&ReadDescriptors) /* clear fd bit */ ; else - ReadDescriptors |= 1 << fd /* set fd bit */ ; + FD_SET(fd,&ReadDescriptors) /* set fd bit */ ; if (fd > HighestFD) HighestFD = fd; @@ -186,7 +189,7 @@ NotUsingFD( nFDsInUse -= 1; FDD[fd].Busy = false; - ReadDescriptors &= ~(1 << fd) /* clear fd bit */ ; + FD_CLR(fd,&ReadDescriptors) /* clear fd bit */ ; while (!FDD[HighestFD].Busy && HighestFD > 0) HighestFD -= 1; @@ -410,24 +413,32 @@ MainLoop(void) while (true) { - int rfds, wfds, xfds; + fd_set rfds, wfds, xfds; short nfds; short fd; /* wait for something */ - rfds = ReadDescriptors & ~BlockedReadDescriptors; - wfds = ReadDescriptors & WriteDescriptors; + + /* rfds = ReadDescriptors & ~BlockedReadDescriptors; */ + rfds = ReadDescriptors; + XFD_UNSET(&rfds, &BlockedReadDescriptors); + xfds = rfds; + /* wfds = ReadDescriptors & WriteDescriptors; */ + XFD_ANDSET(&wfds, &ReadDescriptors, &WriteDescriptors); + + debug(128,(stderr, "select %d, rfds = 0%o\n", HighestFD + 1, rfds)); - if (Interrupt || (rfds == 0 && wfds == 0)) + if (Interrupt || (!XFD_ANYSET(&rfds) && !XFD_ANYSET(&wfds))) { ReadCommands (); Interrupt = 0; continue; } nfds = select(HighestFD + 1, &rfds, &wfds, &xfds, (struct timeval *)NULL); - debug(128,(stderr, "select nfds = 0%o, rfds = 0%o, 0%o, xfds 0%o\n", + debug(128,(stderr, + "select nfds = 0%o, rfds = 0%o, wfds = 0%o, xfds = 0%o\n", nfds, rfds, wfds, xfds)); if (nfds < 0) @@ -469,7 +480,7 @@ MainLoop(void) starvation of later clients by earlier clients */ - if (rfds & (1 << fd)) + if (FD_ISSET(fd,&rfds)) { if (FDD[fd].InputHandler == NULL) { @@ -479,7 +490,7 @@ MainLoop(void) else (FDD[fd].InputHandler)(fd); } - if (wfds & (1 << fd)) + if (FD_ISSET(fd,&wfds)) { if (FDD[fd].FlushHandler == NULL) { diff --git a/fd.h b/fd.h index 3f2da68..bd4f262 100644 --- a/fd.h +++ b/fd.h @@ -88,9 +88,9 @@ extern short MaxFD /* maximum number of FD's possible */ ; extern short nFDsInUse /* number of FD's actually in use */ ; -extern long ReadDescriptors /* bit map of FD's in use -- for select */ ; -extern long WriteDescriptors /* bit map of write blocked FD's -- for select */; -extern long BlockedReadDescriptors /* bit map of FD's blocked from reading */; +extern fd_set ReadDescriptors /* bit map of FD's in use -- for select */ ; +extern fd_set WriteDescriptors /* bit map of write blocked FD's -- for select */; +extern fd_set BlockedReadDescriptors /* bit map of FD's blocked from reading */; extern short HighestFD /* highest FD in use -- for select */ ; /* need to change the MaxFD to allow larger number of fd's */ diff --git a/scope.c b/scope.c index 9596042..3a30ce1 100644 --- a/scope.c +++ b/scope.c @@ -106,9 +106,9 @@ int Interrupt = 0; struct FDDescriptor *FDD = 0; short MaxFD = 0; short nFDsInUse = 0; -long ReadDescriptors = 0; -long WriteDescriptors = 0; -long BlockedReadDescriptors; +fd_set ReadDescriptors; +fd_set WriteDescriptors; +fd_set BlockedReadDescriptors; short HighestFD; short debuglevel = 0; @@ -1075,17 +1075,20 @@ FlushFD ( } if (FDinfo[fd].bufstart == FDinfo[fd].bufcount) { - if (PeerFD >= 0) - BlockedReadDescriptors &= ~ (1 << PeerFD); - WriteDescriptors &= ~(1 << fd); + if (PeerFD >= 0) { + FD_CLR(PeerFD, &BlockedReadDescriptors); + } + FD_CLR(fd, &WriteDescriptors); FDinfo[fd].bufcount = FDinfo[fd].bufstart = 0; } else { - if (PeerFD >= 0) - BlockedReadDescriptors |= 1 << PeerFD; - if (FDinfo[fd].buflimit != FDinfo[fd].bufdelivered) - WriteDescriptors |= 1 << fd; + if (PeerFD >= 0) { + FD_SET(PeerFD, &BlockedReadDescriptors); + } + if (FDinfo[fd].buflimit != FDinfo[fd].bufdelivered) { + FD_SET(PeerFD, &WriteDescriptors); + } } } -- cgit v1.2.1