Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!ucsd!ucbvax!BRL.MIL!mike From: mike@BRL.MIL (Mike Muuss) Newsgroups: comp.sys.sgi Subject: Re: How to do non-blocking keyboard input Message-ID: <9006140143.aa19050@WOLF.BRL.MIL> Date: 14 Jun 90 05:43:44 GMT Sender: usenet@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 90 The best way to do it is to use the select() system call. Here is a portable subroutine that will show you how to do it. Best, -Mike ------- /* * B S D S E L E C T * * Ordinarily, a stub for select() could have been implemented here, * but the IRIS defines a graphics library routine select(). * On non-BSD systems, select() is a name likely to have been reused, * so this special interface has been created. This also has the slight * advantage of centralizing the struct timeval stuff. */ #if defined(BSD) # include /* for fd_set macros */ #endif #if defined(BSD) || defined(CRAY) # include /* for struct timeval. Includes */ #else # include #endif #if defined(sgi) # if !defined(mips) || defined(SGI4D_Rel2) /* 3D systems, and Rel2 4D systems. */ # include # include # else /* Rel3 4D systems got it right */ # include # include # endif #endif #ifdef stellar # include #endif #ifdef FD_SET /* The 4.3 BSD version */ bsdselect( readfds, sec, us ) long readfds; { fd_set fdset; int width; struct timeval tv; int ret; tv.tv_sec = sec; tv.tv_usec = us; if( (width = getdtablesize()) <= 0 ) width = 32; FD_ZERO( &fdset ); fdset.fds_bits[0] = readfds; /* peek inside! */ if( (ret = select( width, &fdset, (fd_set *)0, (fd_set *)0, &tv )) <= 0 ) { if( ret < 0 ) perror("bsdselect/select"); return(0); /* no bits ready */ } readfds = fdset.fds_bits[0]; return( readfds ); } #else /* The old version */ bsdselect( readfds, sec, us ) long readfds; { #if defined(BSD) || defined(sgi) || defined(stellar) || defined(CRAY) struct timeval tv; int ret; long mask; tv.tv_sec = sec; tv.tv_usec = us; mask = readfds; if( (ret = select( 32, &mask, 0L, 0L, &tv )) <= 0 ) { if( ret < 0 ) perror("bsdselect/select"); return(0); /* No bits ready */ } return( mask ); #else return(32-1); /* SYSV always has lots of input */ #endif } #endif /* FD_SET */