Return to BSD News archive
Newsgroups: comp.unix.bsd Path: sserve!newshost.anu.edu.au!munnari.oz.au!network.ucsd.edu!usc!howland.reston.ans.net!noc.near.net!uunet!psinntp!uuneo!sugar!peter From: peter@NeoSoft.com (Peter da Silva) Subject: Re: Timed fgets Organization: NeoSoft Communications Services -- (713) 684-5900 Date: Sun, 11 Jul 1993 22:37:31 GMT Message-ID: <CA0uuL.2o1@sugar.NeoSoft.COM> Keywords: fgets fread timed timeout References: <96947@stanton.UUCP> Lines: 32 In article <96947@stanton.UUCP> donegan@stanton.UUCP (Steven P. Donegan) writes: > The condition would be that I've sent a command to the printer but, for > whatever weird reason, the printer fails to respond. I'm now caught in an > fgets that will never return. Don't use buffered I/O while talking to hardware. Use raw reads/writes with a timeout. The simplest and most portable is just to use an alarm: jmp_buf exception; catcher() { longjmp(exception, 1); } ... ... while(setjmp(exception)) { reset_printer(); } send_command_to_printer(); signal(SIGALM, catcher); alarm(timeout_duration); read_response_from_printer(); alarm(0); -- Peter da Silva. <peter@sugar.neosoft.com>. `-_-' Hefur pu fadmad ulfinn i dag? 'U` "Det er min ledsager, det er ikke drikkepenge."