[comp.std.c] sockets and signals

skp@stl.stc.co.uk (Steve Perryman ) (08/08/90)

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.

The signal handler will be :

void catch()
{
   signal(SIGIO,catch) ;
   count++ ;
   ...
   ...
}

I've used fcntl to allow the socket to interrupt :

fcntl(sock,F_SETOWN,getpid()) ;
fcntl(sock,F_SETFL,F_ASYNC) ;
...
...

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 ???



Thanks in advance,

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

diamond@tkou02.enet.dec.com (diamond@tkovoa) (08/10/90)

In article <3292@stl.stc.co.uk> "Steve Perryman " <skp@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.

ANSI C does not provide any way of obtaining information about sockets, or
even to create a socket in the first place.  I have redirected follow-ups
to comp.lang.c because I don't follow the system-specific groups well enough
to know where to put it.  (Sorry.)

One characteristic of signals is that while you are handling a signal, if
more of the same signal arrive, they probably will not even be delivered,
or perhaps one will be delivered.  Nothing prohibits an implementation from
delivering all of them, but most do not do so.

If you want to know how many items are waiting at a socket, you have to
see if there is a socket-related system call to determine this.  Select
can be used to distinguish between zero and non-zero (and I've never had
to know the exact quantity).
-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.