how do you time-out on a read?

Tappan at BBNG.ARPA Tappan at BBNG.ARPA
Thu Jul 28 06:32:08 AEST 1983


From:  Dan Tappan <Tappan at BBNG.ARPA>

It seems to me that setjmp/longjmp won't work for timing out a read
if you don't want to lose data. There's a potential race condition.
eg. if you have code like

	nread = 0;
	if (!setjmp(env))
	{
	   alarm(XXX);
	   nread = read(..)  /* (1) */;
	   alarm(0);
	   }

	if (nread > 0) { /* process data */ }


if the alarm goes off in the middle of statement (1), after the read
completes but before 'nread' gets set, then that buffer of data
will be lost.

However I'm not familiar with the UNIX kernal signal handling code. Is it
guaranteed that that statement won't be interrupted?

Dan
-------



More information about the Comp.unix.wizards mailing list