From b234064d91924a86dffd3f60f96588097f9dff47 Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Tue, 8 Dec 2020 19:26:56 -0800 Subject: [PATCH] Rework handling of I/O via select() to use correct fd_set type instead of int for fd sets. Some code that was maintaining an fd_set with only a single fd was replaced with just the fd as int, which can be added to the global fd_set as needed. More testing is required for less usual configurations such as host TCP/UDP/IP and direct ethernet (packet filter or NIT) I/O. modified: src/common.c modified: src/ether.c modified: src/inet.c modified: src/initkbd.c modified: src/kbdsubrs.c modified: src/keyevent.c modified: src/main.c modified: src/osmsg.c modified: src/rawrs232c.c modified: src/rpc.c modified: src/rs232c.c modified: src/tty.c modified: src/uraid.c modified: src/xinit.c --- src/common.c | 4 +++- src/ether.c | 27 +++++++++++--------------- src/inet.c | 16 +++++++++------- src/initkbd.c | 3 ++- src/kbdsubrs.c | 9 ++++++--- src/keyevent.c | 51 ++++++++++++++++++++++++++++++++----------------- src/main.c | 5 ++++- src/osmsg.c | 15 ++++++++------- src/rawrs232c.c | 23 +++++++++++----------- src/rpc.c | 19 +++++++++--------- src/rs232c.c | 14 ++++++-------- src/tty.c | 7 ++++--- src/uraid.c | 13 +++++++------ src/xinit.c | 5 +++-- 14 files changed, 117 insertions(+), 94 deletions(-) diff --git a/src/common.c b/src/common.c index bf725a7..f0aba93 100644 --- a/src/common.c +++ b/src/common.c @@ -16,6 +16,7 @@ static char *id = "$Id: common.c,v 1.2 1999/01/03 02:06:52 sybalsky Exp $ Copyri #include #include #include /* for memset */ +#include /* for fd_set */ #include "lispemul.h" #include "lispmap.h" #include "adr68k.h" @@ -45,7 +46,8 @@ error ******************************************************************/ #define URMAXFXNUM 100 -extern unsigned int LispReadFds, LispWindowFd, LispKbdFd; +extern fd_set LispReadFds; +extern int LispWindowFd, LispKbdFd; extern struct screen LispScreen; extern int displaywidth, displayheight; extern DLword *DisplayRegion68k; diff --git a/src/ether.c b/src/ether.c index 3b7346a..0e51b85 100644 --- a/src/ether.c +++ b/src/ether.c @@ -27,6 +27,7 @@ static char *id = "$Id: ether.c,v 1.4 2001/12/24 01:09:02 sybalsky Exp $ Copyrig #include #include #include +#include #ifndef NOETHER #include #include @@ -73,8 +74,6 @@ static char *id = "$Id: ether.c,v 1.4 2001/12/24 01:09:02 sybalsky Exp $ Copyrig #define NIOCSETF PFIOCSETF #endif -u_int EtherReadFds; - int ether_fd = -1; /* file descriptor for ether socket */ int ether_intf_type = 0; u_char ether_host[6] = {0, 0, 0, 0, 0, 0}; /* 48 bit address of this node */ @@ -83,7 +82,7 @@ int ether_bsize = 0; /* if nonzero then a receive is pending */ u_char *ether_buf; /* address of receive buffer */ u_char nit_buf[3000]; /* the current chunk read from NIT (one packet) */ extern LispPTR *PENDINGINTERRUPT68k; -extern u_int LispReadFds; +extern fd_set LispReadFds; int ETHEREventCount = 0; @@ -508,13 +507,13 @@ LispPTR check_ether() { #ifndef NOETHER #ifndef PKTFILTER - static int rfds; + fd_set rfds; int result, fromlen; struct nit_hdr header; int posi, i; #else /* PKTFILTER */ - static int rfds; + fd_set rfds; int result; int i; int plen; @@ -522,7 +521,7 @@ LispPTR check_ether() { char ctlbuf[2000]; #endif /* PKTFILTER */ - rfds = EtherReadFds; + FD_SET(ether_fd, &rfds); #ifndef PKTFILTER i = 2; if (/* select(32, &rfds, NULL, NULL, &EtherTimeout) >= 0 ) */ (1)) { @@ -573,7 +572,7 @@ LispPTR check_ether() { if (ether_fd >= 0 && ether_bsize > 0 /* && select(32, &rfds, NULL, NULL, &EtherTimeout) >= 0 * -- [on '90/02/14: getsignsldata() chech this] */ - && (rfds & (1 << ether_fd))) { + && (FD_ISSET(ether_fd, &rfds))) { data.maxlen = sizeof(nit_buf); data.len = 0; data.buf = (char *)nit_buf; @@ -617,13 +616,13 @@ LispPTR check_ether() { LispPTR get_packet() { #ifndef NOETHER #ifndef PKTFILTER - static int rfds; + fd_set rfds; int result, fromlen; struct nit_hdr header; int posi, i; #else /* PKTFILTER */ - static int rfds; + fd_set rfds; int result; int i; int plen; @@ -988,15 +987,12 @@ void init_ether() { nioc.nioc_flags = 0; if (ioctl(ether_fd, SIOCSNIT, &nioc) != 0) { printf("init_ether: ioctl failed\n"); - close(ether_fd); ether_fd = -1; return; } #else /* PKTFILTER */ - EtherReadFds |= (1 << ether_fd); - /* first and foremost, flush out ether_fd's buffers and filter it */ /* install packetfilter that rejects everything */ #ifdef USE_DLPI @@ -1024,7 +1020,6 @@ void init_ether() { #endif /* USE_DLPI */ #endif /* PKTFILTER -- jds 23 sep 96 unmatched if fix */ #ifndef PKTFILTER - EtherReadFds |= (1 << ether_fd); if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | FASYNC | FNDELAY) < 0) perror("Ether setup SETFLAGS fcntl"); if (fcntl(ether_fd, F_SETOWN, getpid()) < 0) perror("Ether setup SETOWN"); @@ -1037,7 +1032,7 @@ void init_ether() { if (ioctl(ether_fd, I_FLUSH, (char *)FLUSHR) < 0) { perror("init_ether I_FLUSH"); } #else { - int rfds = EtherReadFds; + FD_SET(ether_fd, &rfds); while (select(32, &rfds, NULL, NULL, &EtherTimeout) > 0) read(ether_fd, nit_buf, sizeof(nit_buf)); } @@ -1082,8 +1077,8 @@ void init_ether() { #endif /* USE_DLPI */ #endif /* PKTFILTER */ - if (EtherReadFds == 0) error("EtherReadFds is zero, but enet opened??"); - LispReadFds |= EtherReadFds; + if (ether_fd < 0) error ("ether_fd is -1, but enet opened??"); + FD_SET(ether_fd, &LispReadFds); DBPRINT(("init_ether: **** Ethernet starts ****\n")); } diff --git a/src/inet.c b/src/inet.c index 8f43f04..d527417 100644 --- a/src/inet.c +++ b/src/inet.c @@ -17,6 +17,7 @@ static char *id = "$Id: inet.c,v 1.3 2001/12/24 01:09:03 sybalsky Exp $ Copyrigh #include #include #include +#include /* for FD_ fns */ #ifdef ISC #include #include @@ -88,8 +89,9 @@ static char *id = "$Id: inet.c,v 1.3 2001/12/24 01:09:03 sybalsky Exp $ Copyrigh #define UDPSendto 130 #define UDPRecvfrom 131 -extern u_int LispIOFds, LispReadFds; extern int *Lisp_errno; +extern fd_set LispReadFds; +fd_set LispIOFds; LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, LispPTR bufaddr, LispPTR maxlen) { @@ -233,8 +235,8 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li case TCPclose: sock = LispNumToCInt(nameConn); - LispIOFds &= ~(1 << sock); - LispReadFds &= ~(1 << sock); + FD_CLR(sock, &LispIOFds); + FD_CLR(sock, &LispReadFds); shutdown(sock, 2); close(sock); return (ATOM_T); @@ -290,8 +292,8 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li sigsetmask(oldmask); #endif /* SYSVSIGNALS */ } - LispIOFds |= (1 << result); /* so we get interrupts */ - LispReadFds |= LispIOFds; + FD_SET(result, &LispIOFds); /* so we get interrupts */ + FD_SET(result, &LispReadFds); DBPRINT(("LispIOFds = 0x%x.\n", LispIOFds)); return (GetSmallp(result)); break; @@ -370,8 +372,8 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li #endif /* RS6000 */ - LispIOFds |= (1 << result); /* so we get interrupts */ - LispReadFds |= LispIOFds; + FD_SET(result, &LispIOFds); /* so we get interrupts */ + FD_SET(result, &LispReadFds); DBPRINT(("LispIOFds = 0x%x.\n", LispIOFds)); return (GetSmallp(result)); break; diff --git a/src/initkbd.c b/src/initkbd.c index 8eafa2b..dba22cc 100644 --- a/src/initkbd.c +++ b/src/initkbd.c @@ -18,6 +18,7 @@ static char *id = "$Id: initkbd.c,v 1.2 1999/01/03 02:07:09 sybalsky Exp $ Copyr #endif #ifndef DOS #include +#include #endif /* DOS */ #ifdef SUNDISPLAY #include @@ -135,7 +136,7 @@ extern int errno; int DebugKBD = NIL; FILE *KBlog; -u_int LispReadFds = 0; +extern fd_set LispReadFds; #ifdef SUNDISPLAY struct inputmask LispEventMask; #endif /* SUNDISPLAY */ diff --git a/src/kbdsubrs.c b/src/kbdsubrs.c index 71c34b0..c4dbd6a 100644 --- a/src/kbdsubrs.c +++ b/src/kbdsubrs.c @@ -19,6 +19,7 @@ static char *id = "$Id: kbdsubrs.c,v 1.2 1999/01/03 02:07:10 sybalsky Exp $ Copy #include #include #include +#include #endif /* DOS */ #ifdef SUNDISPLAY @@ -32,6 +33,7 @@ static char *id = "$Id: kbdsubrs.c,v 1.2 1999/01/03 02:07:10 sybalsky Exp $ Copy #include "kbdsubrsdefs.h" #include "commondefs.h" #ifdef XWINDOW +#include "lisp2cdefs.h" #include "xwinmandefs.h" #endif @@ -65,7 +67,8 @@ extern struct screen LispScreen; #include #endif /* XWINDOW */ -extern int LispWindowFd, LispReadFds; +extern int LispWindowFd; +extern fd_set LispReadFds; extern int errno; @@ -76,7 +79,7 @@ void KB_enable(LispPTR *args) /* args[0] : ON/OFF flag { if (args[0] == ATOM_T) #ifdef SUNDISPLAY - LispReadFds |= 1 << LispWindowFd; + FD_SET(LispWindowFd, &LispReadFds); #elif XWINDOW enable_Xkeyboard(currentdsp); #elif DOS @@ -86,7 +89,7 @@ void KB_enable(LispPTR *args) /* args[0] : ON/OFF flag else if (args[0] == NIL) #ifdef SUNDISPLAY - LispReadFds &= ~(1 << LispWindowFd); + FD_SET(LispWindowFd, &LispReadFds); #elif XWINDOW disable_Xkeyboard(currentdsp); #elif DOS diff --git a/src/keyevent.c b/src/keyevent.c index b74f95a..7eb035c 100644 --- a/src/keyevent.c +++ b/src/keyevent.c @@ -20,9 +20,11 @@ static char *id = "$Id: keyevent.c,v 1.3 2001/12/24 01:09:03 sybalsky Exp $ Copy #include #include #include +#include #ifndef DOS #include #include +#include #include #else #include @@ -143,20 +145,21 @@ struct pollfd pollfds[33] = { extern DLword *EmMouseX68K, *EmMouseY68K, *EmKbdAd068K, *EmRealUtilin68K, *EmUtilin68K; extern DLword *EmKbdAd168K, *EmKbdAd268K, *EmKbdAd368K, *EmKbdAd468K, *EmKbdAd568K; extern u_char *SUNLispKeyMap; -extern u_int LispReadFds, LispWindowFd; -extern int RS232CReadFds, RS232C_remain_data, XLocked; +extern int LispWindowFd; +extern int RS232C_Fd, RS232C_remain_data, XLocked; +extern fd_set LispIOFds; +fd_set LispReadFds; int XNeedSignal = 0; /* T if an X interrupt happened while XLOCK asserted */ #ifdef NOETHER extern u_int LogFileFd; #else extern int ether_fd; -extern u_int LogFileFd, EtherReadFds; +extern u_int LogFileFd; #endif /* NOETHER */ extern DLword *DisplayRegion68k; -u_int LispIOFds = 0; #ifndef DOS static struct timeval SelectTimeout = {0, 0}; #endif /* DOS */ @@ -278,6 +281,7 @@ DLword ColorCursor_savebitmap[CURSORWIDTH / COLORPIXELS_IN_DLWORD * CURSORHEIGHT /* */ /* Statics: LispReadFds A 32-bit vector with a 1 for each */ /* FD that can get SIGIO interrupts. */ +/* 12/04/2020 - now an fd_set */ /* */ /* LispWindowFd The keyboard/window FD, for keyboard */ /* and mouse events. */ @@ -286,14 +290,17 @@ DLword ColorCursor_savebitmap[CURSORWIDTH / COLORPIXELS_IN_DLWORD * CURSORHEIGHT /* FDs Lisp is doing async I/O on. */ /* Activity on any of these will signal */ /* the Lisp IOInterrupt interrupt. */ +/* 12/04/2020 - now an fd_set */ /* */ /* ether_fd The raw ethernet FD, for 10MB I/O */ /* */ /* EtherReadFds A bit vector with the raw enet's */ /* bit turned on. To speed up processing. */ +/* 12/04/2020 - now obsolete */ /* */ /* LogFileFd A bit vector with the log-file's */ /* bit on, for capturing console msgs. */ +/* 12/04/2020 - now just the FD number */ /* */ /* */ /* */ @@ -305,12 +312,13 @@ void getsignaldata(int sig, int code, void *scp) #ifndef XWINDOW struct inputevent event; #endif /* XWINDOW */ - - static int rfds, wfds, efds, res; - + fd_set rfds, efds; + u_int iflags; + int i; #ifdef ISC int fdcount = 0; int bit; + int res; #endif #ifdef XWINDOW @@ -327,22 +335,26 @@ void getsignaldata(int sig, int code, void *scp) #endif /* XWINDOW */ /* #ifndef KBINT */ - rfds = LispReadFds; - efds = LispReadFds; + /* FD_COPY would be preferred but uses deprecated bcopy() on macOS. Why? */ + memcpy(&rfds, &LispReadFds, sizeof(rfds)); + memcpy(&efds, &LispReadFds, sizeof(efds)); + /* label and ifs not needed if only keyboard on SIGIO */ getmore: #ifdef ISC for (res = 0, bit = 1; res < 32; res++, bit <<= 1) - if (LispReadFds & bit) { pollfds[fdcount++].fd = res; } + if (FD_ISSET(bit, &LispReadFds)) { pollfds[fdcount++].fd = res; } if ((res = poll(pollfds, fdcount, 0)) > 0) #else - if (select(32, (fd_set *)&rfds, NULL, (fd_set *)&efds, &SelectTimeout) >= 0) + if (select(32, &rfds, NULL, &efds, &SelectTimeout) >= 0) #endif { + /* need to print out fd sets... DBPRINT(("SIGIO: fd mask(r/e) = 0x%x/0x%x.\n", rfds, efds)); + */ #ifdef SUNDISPLAY - if (rfds & (1 << LispWindowFd)) { + if (FD_ISSET(LispWindowFd, &rfds)) { /* #endif */ while (input_readevent(LispWindowFd, &event) >= 0) { /*if(!kb_event( &event )) {goto getmore;};*/ @@ -356,7 +368,7 @@ getmore: #endif /* SUNDISPLAY */ #ifdef XWINDOW - if (rfds & (1 << ConnectionNumber(currentdsp->display_id))) { + if (FD_ISSET(ConnectionNumber(currentdsp->display_id), &rfds)) { if (!XLocked) getXsignaldata(currentdsp); else @@ -367,19 +379,19 @@ getmore: #ifdef NOETHER #else - if (rfds & EtherReadFds) { /* Raw ethernet (NIT) I/O happened, so handle it. */ + if (FD_ISSET(ether_fd, &rfds)) { /* Raw ethernet (NIT) I/O happened, so handle it. */ DBPRINT(("Handling enet interrupt.\n\n")); check_ether(); } #endif /* NOETHER */ #ifdef RS232 - if (((rfds & RS232CReadFds) == RS232CReadFds) || (RS232C_remain_data && rs232c_lisp_is_ready())) + if (FD_ISSET(RS232C_Fd, &rfds) || (RS232C_remain_data && rs232c_lisp_is_ready())) rs232c_read(); #endif /* RS232 */ #ifdef LOGINT - if (rfds & LogFileFd) { /* There's info in the log file. Tell Lisp to print it. */ + if (FD_ISSET(LogFileFd, &rfds)) { /* There's info in the log file. Tell Lisp to print it. */ flush_pty(); /* move the msg(s) to the log file */ ((INTSTAT *)Addr68k_from_LADDR(*INTERRUPTSTATE_word))->LogFileIO = 1; @@ -388,10 +400,13 @@ getmore: Irq_Stk_End = Irq_Stk_Check = 0; } #endif - if (rfds & LispIOFds) { /* There's activity on a Lisp-opened FD. Tell Lisp. */ + iflags = 0; + for (i = 0; i < 32; i++) + if (FD_ISSET(i, &rfds) & FD_ISSET(i, &LispIOFds)) iflags |= 1 << i; + if (iflags) { /* There's activity on a Lisp-opened FD. Tell Lisp. */ u_int *flags; flags = (u_int *)Addr68k_from_LADDR(*IOINTERRUPTFLAGS_word); - *flags = rfds & LispIOFds; + *flags = iflags; ((INTSTAT *)Addr68k_from_LADDR(*INTERRUPTSTATE_word))->IOInterrupt = 1; diff --git a/src/main.c b/src/main.c index 7a2eab4..ac1ddf4 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,7 @@ static char *id = "$Id: main.c,v 1.4 2001/12/26 22:17:03 sybalsky Exp $ Copyrigh #ifndef DOS #include +#include #endif /* DOS */ #include @@ -358,7 +359,7 @@ int main(int argc, char *argv[]) char *envname; extern int TIMER_INTERVAL; char keytyped[255]; - + extern fd_set LispReadFds; #ifndef NOFORN if (dld_find_executable(argv[0]) == 0) { perror("Name of executable not found."); @@ -532,6 +533,8 @@ int main(int argc, char *argv[]) strcpy(keytyped, keystring); + FD_ZERO(&LispReadFds); + #ifndef NOETHER init_ether(); /* modified by kiuchi Nov. 4 */ #endif /* NOETHER */ diff --git a/src/osmsg.c b/src/osmsg.c index eca75e4..5c384b8 100644 --- a/src/osmsg.c +++ b/src/osmsg.c @@ -24,6 +24,7 @@ static char *id = "$Id: osmsg.c,v 1.2 1999/01/03 02:07:29 sybalsky Exp $ Copyrig #include #include +#include #include #ifdef ISC #include @@ -79,7 +80,7 @@ int previous_size; int logChanged; /* T if log file has changed since last READ */ /* Set by flush_pty, to avoid the stat call */ u_int LogFileFd; -extern u_int LispReadFds; +extern fd_set LispReadFds; /************************************************************************/ /* */ @@ -162,7 +163,7 @@ gotpty: if ((log_id = open(logfile, (O_RDWR | O_CREAT), 0666)) < 0) return; #ifdef LOGINT - LogFileFd = 1 << cons_pty; + LogFileFd = cons_pty; /* was kept as an fd_set, but doesn't need to be */ flags = fcntl(cons_pty, F_GETFL, 0); flags = fcntl(cons_pty, F_SETFL, (flags | FASYNC | FNDELAY)); if (fcntl(cons_pty, F_SETOWN, getpid()) == -1) { @@ -170,7 +171,7 @@ gotpty: perror("fcntl F_SETOWN of log PTY"); #endif }; - LispReadFds |= LogFileFd; + FD_SET(LogFileFd, &LispReadFds); flush_pty(); #endif previous_size = 0; @@ -344,7 +345,7 @@ LispPTR flush_pty() { struct stat sbuf; char buf[MESSAGE_BUFFER_SIZE]; /* Buffer between pty and log file */ int size; - static int rfds; + static fd_set rfds; int rval; struct statfs fsbuf; @@ -352,10 +353,10 @@ LispPTR flush_pty() { DBPRINT(("flush_pty() called.\n")); /* polling pty nd flush os message to log file */ #ifndef LOGINT - rfds = (1 << cons_pty); - if (select(32, &rfds, NULL, NULL, &selecttimeout) < 0) return (NIL); + FD_SET(cons_pty, &rfds); + if (select(32, &rfds, NULL, NULL, &selecttimeout) <= 0) return (NIL); - if ((cons_pty >= 0) && (rfds & (1 << cons_pty))) + if ((cons_pty >= 0) && FD_ISSET(cons_pty, rfds)) #else /* LOGINT */ if ((cons_pty >= 0) && ((size = read(cons_pty, buf, MESSAGE_BUFFER_SIZE - 1)) > 0)) diff --git a/src/rawrs232c.c b/src/rawrs232c.c index ebd08d5..5df6b23 100644 --- a/src/rawrs232c.c +++ b/src/rawrs232c.c @@ -11,6 +11,7 @@ static char *id = "$Id: rawrs232c.c,v 1.2 1999/01/03 02:07:31 sybalsky Exp $ Cop #include "version.h" +#include #include #include #include @@ -261,13 +262,13 @@ LispPTR raw_rs232c_read(LispPTR fd, LispPTR buff, LispPTR nbytes) unsigned char *buffptr; int length; u_int real_fd; - u_int readfds; + fd_set readfds; - real_fd = fd & 0xffff; - readfds = (1 << real_fd); + real_fd = fd & 0xffff; /* FIXME: should be GetSmallp() ? */ + FD_SET(real_fd, &readfds); select(32, &readfds, NULL, NULL, &RS_TimeOut); - if (readfds & (1 << real_fd)) { + if (FD_ISSET(real_fd, &readfds)) { buffptr = (unsigned char *)Addr68k_from_LADDR(buff); if ((length = read(real_fd, buffptr, (nbytes & 0xffff))) < 0) { @@ -285,20 +286,20 @@ LispPTR raw_rs232c_read(LispPTR fd, LispPTR buff, LispPTR nbytes) LispPTR raw_rs232c_setint(LispPTR fd, LispPTR onoff) { - extern u_int LispReadFds; - extern u_int LispIOFds; + extern fd_set LispReadFds; + extern fd_set LispIOFds; u_int real_fd; - real_fd = (fd & 0xffff); + real_fd = (fd & 0xffff); /* FIXME: should be GetSmallp() */ if (onoff == ATOM_T) { - LispReadFds |= (1 << real_fd); - LispIOFds |= (1 << real_fd); + FD_SET(real_fd, &LispReadFds); + FD_SET(real_fd, &LispIOFds); int_io_open(real_fd); } else { int_io_close(real_fd); - LispReadFds &= ~(1 << real_fd); - LispIOFds &= ~(1 << real_fd); + FD_CLR(real_fd, &LispReadFds); + FD_CLR(real_fd, &LispIOFds); } return (ATOM_T); } diff --git a/src/rpc.c b/src/rpc.c index 744d6ef..5c6c505 100644 --- a/src/rpc.c +++ b/src/rpc.c @@ -24,6 +24,7 @@ static char *id = "$Id: rpc.c,v 1.3 2001/12/24 01:09:06 sybalsky Exp $ Copyright #include #include #include +#include #include #include #include @@ -70,11 +71,11 @@ LispPTR rpc(LispPTR *args) struct sockaddr_in sin, sin1, from; char *outbuf, *inbuf, *destaddr; register int s, msec_until_timeout, msec_between_tries, out_length; - register int received, mask; + register int received; register int port; - int dontblock, dest, read_descriptors; + int dontblock, dest; unsigned fromlen; - + fd_set read_descriptors; struct timeval pertry_timeout, total_timeout, time_waited; /* Set timeout */ @@ -145,9 +146,6 @@ LispPTR rpc(LispPTR *args) if (sendto(s, outbuf, out_length, 0, (struct sockaddr *)&sin1, sizeof(sin1)) != out_length) goto handle_error; - /* Set the select mask */ - mask = 1 << s; - /* Set up the timers */ time_waited.tv_sec = 0; time_waited.tv_usec = 0; @@ -155,10 +153,11 @@ LispPTR rpc(LispPTR *args) /* Start the waiting loop */ receive: - read_descriptors = mask; + /* Set the select mask */ + FD_SET(s, &read_descriptors); switch ( - select(32, (fd_set *)&read_descriptors, (fd_set *)NULL, (fd_set *)NULL, &pertry_timeout)) { + select(32, &read_descriptors, NULL, NULL, &pertry_timeout)) { /* Per try timeout expired, Check the total timeout */ case 0: time_waited.tv_sec += pertry_timeout.tv_sec; @@ -184,8 +183,8 @@ receive: else goto handle_error; } - /* Did something arrive for this socket */ - if ((read_descriptors & mask) == 0) goto receive; + /* Nothing arrived for this socket, try again */ + if (!FD_ISSET(s, &read_descriptors)) goto receive; /* Something arrived; try to get it */ diff --git a/src/rs232c.c b/src/rs232c.c index 273bf32..8790f2e 100644 --- a/src/rs232c.c +++ b/src/rs232c.c @@ -10,9 +10,9 @@ static char *id = "$Id: rs232c.c,v 1.2 1999/01/03 02:07:32 sybalsky Exp $ Copyri /************************************************************************/ #include "version.h" - #include "rs232c.h" - +#include "lspglob.h" +#include /* * Lisp Interface */ @@ -28,9 +28,8 @@ static DLword *RS232CGetCSB, *RS232CPutCSB; /* * File descriptor */ -extern int LispReadFds; -static int RS232C_Fd; -int RS232CReadFds; +extern fd_set LispReadFds; +int RS232C_Fd; int RS232C_remain_data; static char *RS232C_Dev; @@ -171,8 +170,7 @@ rs232c_open() { rs_error("RS232C: rs232c_open: cannot set signal"); else { rs_install_hup_handler(); - - LispReadFds |= (RS232CReadFds = 1 << RS232C_Fd); + FD_SET(RS232C_Fd, &LispReadFds); RS232C_remain_data = 0; } } @@ -186,7 +184,7 @@ rs232c_close() { rs_restore_hup_handler(); - LispReadFds &= ~RS232CReadFds; + FD_CLR(RS232C_Fd, &LispReadFds); /* if (close(RS232C_Fd) < 0) diff --git a/src/tty.c b/src/tty.c index 6d829e0..3be69b7 100644 --- a/src/tty.c +++ b/src/tty.c @@ -10,6 +10,7 @@ static char *id = "$Id: tty.c,v 1.2 1999/01/03 02:07:39 sybalsky Exp $ Copyright #include "version.h" +#include #include "tty.h" DLTTY_OUT_COMMAND *DLTTYPortCmd; @@ -18,7 +19,7 @@ DLTTY_OUT_CSB *DLTTYOut; char *TTY_Dev; int TTY_Fd; -extern int LispReadFds; +extern fd_set LispReadFds; struct sgttyb TTY_Mode; void tty_init() { @@ -47,7 +48,7 @@ void tty_open() { TTY_Mode.sg_flags = RAW; stat = ioctl(TTY_Fd, TIOCSETP, &TTY_Mode); - LispReadFds |= (1 << TTY_Fd); + FD_SET(TTY_Fd, &LispReadFds); #ifdef TTYINT int_io_open(TTY_Fd); #endif @@ -66,7 +67,7 @@ void tty_close() { #endif if (TTY_Fd >= 0) { - LispReadFds &= ~(1 << TTY_Fd); + FD_CLR(TTY_Fd, &LispReadFds); stat = close(TTY_Fd); #ifdef TTYINT int_io_close(TTY_Fd); diff --git a/src/uraid.c b/src/uraid.c index 432502a..b952336 100644 --- a/src/uraid.c +++ b/src/uraid.c @@ -39,6 +39,7 @@ static char *id = "@(#) uraid.c 1.52 4/23/92 (Venue & Fuji Xerox)"; #include #include #include +#include #endif /* DOS */ #include #ifndef XWINDOW @@ -164,7 +165,8 @@ extern struct pixrect *ColorDisplayPixrect, *DisplayRegionPixrect; #endif /* NOPIXRECT */ extern int DisplayRasterWidth; -extern unsigned int LispReadFds, LispWindowFd, LispKbdFd; +extern unsigned int LispWindowFd, LispKbdFd; +extern fd_set LispReadFds; #ifndef NOPIXRECT extern struct pixrect *CursorBitMap, *InvisibleCursorBitMap; #endif /* NOPIXRECT */ @@ -173,7 +175,6 @@ extern struct screen LispScreen; extern int displaywidth, displayheight; extern DLword *DisplayRegion68k; extern int FrameBufferFd, ether_fd, RS232C_Fd; -extern u_int EtherReadFds; LispPTR RadiAtomIndex; LispPTR RaidPackageIndex; @@ -1085,7 +1086,7 @@ static int re_init_display(int, int); int device_after_raid() { extern DLword *EmMouseX68K, *EmMouseY68K, *EmKbdAd068K, *EmRealUtilin68K; extern DLword *EmKbdAd168K, *EmKbdAd268K, *EmKbdAd368K, *EmKbdAd468K, *EmKbdAd568K; - LispReadFds = 0; + FD_ZERO(&LispReadFds); if (re_init_display(DISPLAY_OFFSET, 65536 * 16 * 2) == -1) return (-1); set_cursor(); init_keyboard(1); @@ -1118,17 +1119,17 @@ int device_after_raid() { int_init(); #ifdef SUNDISPLAY - LispReadFds |= (1 << LispWindowFd); + FD_SET(LispWindowFd, &LispReadFds); #endif /* SUNDISPLAY */ #ifdef NOETHER #else - LispReadFds |= EtherReadFds; + FD_SET(ether_fd, &LispReadFds); #endif /* NOETHER */ #ifdef XWINDOW (currentdsp->device.after_raid)(currentdsp); - LispReadFds |= (1 << ConnectionNumber(currentdsp->display_id)); + FD_SET(ConnectionNumber(currentdsp->display_id), &LispReadFds); flush_display_buffer(); #elif DOS (currentdsp->device.after_raid)(currentdsp); diff --git a/src/xinit.c b/src/xinit.c index e6d7a9b..6b11c3a 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -39,6 +39,7 @@ static char *id = "$Id: xinit.c,v 1.5 2001/12/26 22:17:06 sybalsky Exp $ Copyrig #include #include +#include #ifndef APOLLO #ifndef HPUX @@ -83,7 +84,7 @@ unsigned LispDisplayRequestedWidth, LispDisplayRequestedHeight; Colormap Colors; int XLocked = 0; /* non-zero while doing X ops, to avoid signals */ -extern int LispReadFds; +extern fd_set LispReadFds; /************************************************************************/ /* */ @@ -203,7 +204,7 @@ void Xevent_after_raid(DspInterface dsp) /************************************************************************/ void Open_Display(DspInterface dsp) { - LispReadFds |= (1 << ConnectionNumber(dsp->display_id)); + FD_SET(ConnectionNumber(dsp->display_id), &LispReadFds); #ifndef ISC #ifndef HPUX fcntl(ConnectionNumber(dsp->display_id), F_SETOWN, getpid());