Xref: utzoo comp.unix.questions:24518 comp.unix.wizards:23375 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!rutgers!usc!wuarchive!decwrl!sun-barr!newstop!sun!snafu!lm From: lm@snafu.Sun.COM (Larry McVoy) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: sockets and signals (in C) Message-ID: <140492@sun.Eng.Sun.COM> Date: 10 Aug 90 18:49:12 GMT References: <3304@stl.stc.co.uk> Sender: news@sun.Eng.Sun.COM Reply-To: lm@sun.UUCP (Larry McVoy) Organization: Sun Microsystems, Mountain View Lines: 38 In article <3304@stl.stc.co.uk> "Steve Perryman " 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@sun.com