I need a SysV select()

Brandon S. Allbery allbery at ncoast.UUCP
Wed May 25 09:45:30 AEST 1988


As quoted from <7904 at brl-smoke.ARPA> by gwyn at brl-smoke.ARPA (Doug Gwyn ):
+---------------
| In article <9738 at sol.ARPA> jpayne at cs.rochester.edu (Jonathan Payne) writes:
| >I want to get input
| >from either the keyboard or from some other file description.  I don't
| >want to sit around polling the two, because that would be ridiculous.
| 
| If you set MIN and TIME to 0 in the terminal handler, then an attempt
| to read from the terminal with no data available will return immediately.
| There is nothing analogous for ordinary files.
+---------------

But that still leaves him polling.

Jon:  It's a bit ironic; the closest thing to a solution is something I've
been planning to do to "portsrv" in the Jove distribution.

Have your files opened by subprocesses:  one process per file.  They should
communicate with the parent process via a message queue.  Each does blocking
reads; when the read succeeds, the process should package it up in a message
with an ID field unique to the file/process (you can use dev/inode, process
ID, or anything else you choose as long as it's unique to each process).

The parent program then does a blocking msgrcv on the message queue.  When a
message comes in, the parent can examine the ID field to determine which
file it got the data from, and process it as appropriate.  If another
message comes in while the parent is processing, it will remain on the queue
until the parent gets around to issuing another msgrcv.

This is, alas, restricted to System V (I can think of some places where it'd
be useful on ncoast, but ncoast is System III).  There is *no* general
solution for System III, Xenix 3 or V7.  (You *could* use a FIFO to fake a
message queue under System III/Xenix 3, but now you're getting into nasty
complications.  And it's far easier to set up a two-way message queue than
it is to coordinate multiple FIFOs in a two-way connection, if you need it.
And FIFOs still aren't in pre-System III *nixes.)
-- 
	      Brandon S. Allbery, moderator of comp.sources.misc
	{well!hoptoad,uunet!marque,cbosgd,sun!mandrill}!ncoast!allbery
Delphi: ALLBERY						     MCI Mail: BALLBERY



More information about the Comp.unix.wizards mailing list