sockets and signals (in C)

Larry McVoy lm at snafu.Sun.COM
Sat Aug 11 04:49:12 AEST 1990


In article <3304 at stl.stc.co.uk> "Steve Perryman " <skp at stl.stc.co.uk> writes:
>
>Does anyone know of a way to set up a signal handler such that if a flood
>of data comes in to a socket, the SIGIO/SIGPOLL (maybe even SIGURG) signal
>can invoke a handler fast enough such that a variable can be incremented to
>represent the correct number of data items at the socket.
>
>This works but it can't log the correct number of items received if they come
>in as bursts of data (5+ items per burst). Can this timing problem be resolved
>using SIGIO , or is another way required ???

This can't be done with Unix signals.  Unix signals don't stack, i.e., if
you hit yout interrupt character several times before the kernel delivers 
the signal, the application will only see one signal.

About the best you can do for you application is to use sigio as a hint that
there is data waiting and schedule a timeout every second or so to collect
what you might have missed.  It's also a good idea to code your processing
like so:


	for ( ;; ) {
		sigpause(0);
		while (more_data()) {
			process_data();
		}
	}

rather than

	for ( ;; ) {
		sigpause(0);
		if (more_data()) {
			process_data();
		}
	}
---
Larry McVoy, Sun Microsystems     (415) 336-7627       ...!sun!lm or lm at sun.com



More information about the Comp.unix.wizards mailing list