Efficiency of detecting input FD after SIGIO?

Thomas Truscott trt at rti.UUCP
Tue Feb 9 02:25:12 AEST 1988


In <108 at titan.SW.MCC.COM>, janssen at 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



More information about the Comp.unix.wizards mailing list