Xref: utzoo comp.sys.ibm.pc.hardware:8879 comp.sys.ibm.pc.programmer:2716 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!apple!equinox!jimi!hammond!elvis From: elvis@hammond.cs.unlv.edu (Frederick Haab) Newsgroups: comp.sys.ibm.pc.hardware,comp.sys.ibm.pc.programmer Subject: Re: How to implement an I/O Timeout Message-ID: <1991May21.204255.21788@unlv.edu> Date: 21 May 91 20:42:55 GMT References: <1991May21.164600.10474@spool.cs.wisc.edu> Sender: news@unlv.edu (News User) Reply-To: elvis@jimi.cs.unlv.edu (Frederick Haab) Distribution: usa Organization: UNLV Computer Science and Electrical Engineering Lines: 26 In article <1991May21.164600.10474@spool.cs.wisc.edu> ttl@aura.cs.wisc.edu (Tony Laundrie) writes: >I am doing some low-level I/O, and if the cables aren't all connected, >then an inp() statement will hang forever. How do I set up a timeout in >Turbo C or Microsoft C? > >I want to say something like: > > settimeout (2, timeout_error); /* in two seconds, > call timeout_error() */ > x = inp (); /* attempt input */ > settimeout (0); /* cancel the timeout, 'cuz > we succeeded */ > >Thanks. Please email--I will post summary. ttl@cs.wisc.edu I posted a small C program a few weeks ago that played music in the background. I'm sure you could use the same method to set a timed delay and then call a subroutine that would just terminate (do an exit(0) or something), but I don't know how you would just get your inp() function to stop. You could try putting a label after your inp() and then maybe *fix* the stack somehow so that it would seem the inp() function was never called. Just a thought... --==-- Frederick Haab --==--