[comp.unix.wizards] Efficiency of detecting input FD after SIGIO?

janssen@titan.SW.MCC.COM (Bill Janssen) (02/08/88)

I have a program that has between 1 and 20 sockets open.
It receives SIGIO when input is available on some one of them.
80% of the time there is only one open socket.
The OS is SunOS 3.4 (BSD 4.2, sort of).

Given this, what is the most efficient way to tell what fd the input
is available on?  Given that only one socket is open most of the time,
should I do an "ioctl (primary_fd, FIONREAD, &count)" on that one,
and do a "select" on the others, if any others are open?  Would a chain
of ioctl's be more efficient?  Should I just do a select on the whole
batch and stop messing around with ioctl's altogether?

By the way, doing a "fcntl (socket_fd, F_SETOWN, getpid())" on a socket
in order to specify that SIGIO's should be delivered when the socket
has something to read, only seems to work when the process is the
process group leader of its process group.  Is this correct behaviour?

Bill Janssen

trt@rti.UUCP (Thomas Truscott) (02/09/88)

In <108@titan.SW.MCC.COM>, janssen@titan.SW.MCC.COM (Bill Janssen) writes:
> I have a program that has between 1 and 20 sockets open.
> It receives SIGIO when input is available on some one of them.
> 80% of the time there is only one open socket.
> Given this, what is the most efficient way to tell what fd the input
> is available on?

Well, it sounds like 80% of the time you *know* what fd the input is available
on, so you can just read the data (you might consider non-blocking I/O).

If there is more than one fd just use select().
Calls like select() are why BSD is so much better than System V.
But if you can't resist optimizing things,
do a (non-blocking) read of the fd you think has the data.
If it indeed has data you avoid the overhead of the select().

I find signal handling to be a dangerous business,
and recommend against it.  Do you really need SIGIO?
What is the program doing in the meantime?
If it is just reading from a terminal, put the select()
on that as well and you win all around.
	Tom Truscott

rml@hpfcdc.HP.COM (Bob Lenk) (02/12/88)

> If there is more than one fd just use select().
> ...
> But if you can't resist optimizing things,
> do a (non-blocking) read of the fd you think has the data.
> If it indeed has data you avoid the overhead of the select().

If there's more than one socket, you should always do a select,
since there may be data on more than one socket.  Remember that
SIGIO signals are not queued.

		Bob Lenk
		{ihnp4, hplabs}!hpfcla!rml