Signal handling on sockets

Mike Lippert lippert at pigpen.rtp.dg.com
Sat Aug 4 11:25:12 AEST 1990


In article <3271 at stl.stc.co.uk> "Steve Perryman " <skp at stl.stc.co.uk> writes:
>
>I have a signal handling problem I am unable to resolve.
>
>I have set up a signal handler to record whenever a socket receives data
>(using the "signal" operation with the SIGIO/SIGPOLL code)
... ...
>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. After putting in a loop
>to delay the transmission of each data item, the signal handler was invoked
>the correct number of times. This suggests a timing/race problem at the
>receiving end.
>
>What I would like to know is how to set the signal handler so it acknowledges
>every signal regardless of the speed and frequency of receipt of data at the
>socket (if this is possible).
>
>Steven Perryman
>(skp at stl.stc.co.uk)


Not that this will necessarily solve your problem (I'm just starting
to play w/ UNIX myself) but as I understand it you should use sigset()
instead of signal().  sigset() does not allow the trap routine to be
interrupted by another of the same signal.  It also (I think) does
not require you to reset the signal handler, within the signal handler
as signal() does.

Also I understand signals in unix, the best you can do is be
handling 1 signal and have 1 pended, any more that arrive while 1 is 
pended will be lost, therefore your signal handler should not expect
1 event per signal, but rather 0+ events, ie you should handle
*all* events waiting including *no* events waiting.
--
Michael J. Lippert ---- internet --> lippert at pigpen.rtp.dg.com



More information about the Comp.lang.c mailing list