#ifndef lint static char sccsid[] = "@(#)select.c 1.1 94/10/31 SMI"; /* from S5R2 1.1 */ #endif /* * Code for various kinds of delays. Most of this is nonportable and * requires various enhancements to the operating system, so it won't * work on all systems. It is included in curses to provide a portable * interface, and so curses itself can use it for function keys. */ #include "curses.ext" #include #define NAPINTERVAL 100 /* From early specs - this may change by 4.2BSD */ struct _timeval { long tv_sec; long tv_usec; }; #ifdef FIONREAD # ifndef TIOCREMOTE /* * Decide if we can emulate select but don't have it. This is * intended to be true only on 4.1BSD, not 4.2BSD or USG. */ # define NEEDSELECT # endif #endif #ifdef NEEDSELECT /* * Emulation of 4.2BSD select system call. This is somewhat crude but * better than nothing. We do FIONREAD on each fd, and if we have to * wait we use nap to avoid a busy wait. The resolution of the nap * will hurt response - so will the fact that we ignore the write fds. * If we are simulating nap with a 1 second sleep, this will be very poor. * * nfds is the number of fds to check - this is usually 20. * prfds is a pointer to a bit vector of file descriptors - in the case * where nfds < 32, prfds points to an integer, where bit 1<tv_sec * 1000 + timeout->tv_usec / 1000; for (;;) { /* check the fds */ for (fd=0; fd 0) { rv++; } else *prfds &= ~(1<