Signal handling on sockets

Steve Perryman skp at stl.stc.co.uk
Thu Aug 2 20:03:12 AEST 1990


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)


static int trapped ;

void trap()
{
   signal(SIGIO,trap) ;
   trapped++ ;
}



I have a socket set up to read data from the internet and have used the "fcntl"
operation to set the owner process and to allow asynchronous IO so the socket
can invoke the signal handler on receipt of data.


signal(SIGIO,trap) ;
...
...
fcntl(socket,F_SETOWN,getpid()) ;
fcntl(socket,F_SETFL,FASYNC) ;
...


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).



Thanks in advance,

Steven Perryman
(skp at stl.stc.co.uk)



More information about the Comp.lang.c mailing list