Xref: utzoo comp.unix.questions:20370 comp.unix.wizards:20871 Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!mcsun!sunic!enea!janne From: janne@enea.se (Jan Carlsson) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: Timed-out Input Keywords: System V - Yes, BSD- ??? Message-ID: <834@enea.se> Date: 3 Mar 90 17:30:14 GMT References: <25DCE6F4.2232@paris.ics.uci.edu> Reply-To: janne@enea.se (Jan Carlsson) Organization: Enea Data AB, Sweden Lines: 37 UUCP-Path: mcvax!kth!sunic!helios!janne In article <25DCE6F4.2232@paris.ics.uci.edu> bvickers@paris.ics.uci.edu (Brett Joseph Vickers) writes: >As you can see, I know of no way to time out raw or cbreaked input. >Is there a way to do this with BSD? You can use select(2): #include #include #include #include main() { struct sgttyb temp; fd_set rset; struct timeval timeout; char c; ioctl(0,TIOCGETP,&temp); temp.sg_flags |= CBREAK; ioctl(0,TIOCSETP,&temp); FD_ZERO(&rset); FD_SET(0,&rset); timeout.tv_sec = 3L; timeout.tv_usec = 0L; if (select(1,&rset,NULL,NULL,&timeout) == 1 && FD_ISSET(0,&rset)) read(0,&c,1); else printf("Timed out\n"); } -- Jan Carlsson, Enea Data AB, Box 232, Nytorpsvaegen 5, S-183 23 Taeby, Sweden Phone: +46 8 792 25 00 ! e-mail: janne@enea.se Fax: +46 8 768 43 88 !