Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!LL.MIT.EDU!preston From: preston@LL.MIT.EDU (Steven Preston) Newsgroups: comp.sys.next Subject: Re: Read timeouts in threads Message-ID: <9102210916.AA22089@LL.MIT.EDU> Date: 21 Feb 91 14:16:59 GMT Sender: daemon@ucbvax.BERKELEY.EDU Followup-To: comp.sys.next Lines: 40 > In article <12395@sybase.sybase.com> tim@ohday.sybase.com (Tim Wood) writes: >>Does NeXT have the select() system call? > I have thought of two solutions > 1. Using Unix's alarm and signal. > 2. Read only when there is data in the serial port. [Use DPSAddFD] NeXT DOES have a select() system call. There is no need to kludge with the alarms and signals of (1). If you are working on an appkit application then (2) is the easiest way to go. OTOH, if you are working on a traditional UNIX filter-type app, then you would probably want to use select(). I have written a class, called Fdset (for file descriptor set), which can be used to register any number of file descriptors and will wait for input with or without timing out. Here is the Fdset.h file. ------------------------------------------------------------------------ #import #import @interface Fdset:Object { fd_set fds; // holds the file descriptors this set will wait on fd_set ready_fds; // holds only those file descriptors which are ready for reading int nfds; // the largest fd in the set plus 1 } + new; - addfd:(int)thisfd; - (BOOL) isfdReady:(int)thisfd; // returns YES if given descriptor is ready - (int) waitOnInputForever; // returns number of file descriptors which are ready - (int) waitOnInputFor:(int)seconds; //waits no more than number of seconds - (int) waitOnInputFor:(int)seconds :(int)microseconds; // for fractional timeouts - (int) getReadyfd; //returns one of the ready file descriptors, marks it unready @end ------------------------------------------------------------------------ It is trivial to write the methods, after reading the select man page. -- Steve Preston Brought to you by Super Global Mega Corp .com