Signal handling on sockets

Richard Tobin richard at aiai.ed.ac.uk
Sat Aug 4 01:47:22 AEST 1990


In article <3271 at stl.stc.co.uk> "Steve Perryman " <skp at stl.stc.co.uk> writes:
>The problem I have is that my test harness sends n messages to the socket in
>succession (the real application could receive any number of data items at any
>time) and the signal handler is invoked ONCE ONLY.

Assuming you're using a system with BSD-style signals, you can expect
that (1) SIGIO will be blocked during execution of your signal handler
and (2) if data arrives while the signal is blocked you will receive
precisely one SIGIO when your handler returns, regardless of how
many things arrived during the handler.

If you're reading the data inside the handler, you should read everything
there is, not just one "item".

This will mean that you might get a signal after you've read the
corresponding data, so be prepared for nothing to be waiting.

You can use either select() with a zero timeout or non-blocking i/o
for this.

-- Richard
-- 
Richard Tobin,                       JANET: R.Tobin at uk.ac.ed             
AI Applications Institute,           ARPA:  R.Tobin%uk.ac.ed at nsfnet-relay.ac.uk
Edinburgh University.                UUCP:  ...!ukc!ed.ac.uk!R.Tobin



More information about the Comp.lang.c mailing list