[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [smh@Franz.COM: Re: [spr7955] named pipes question]



> 
> Unix has two kinds of system calls, "slow" calls that are potentially
> interruptible (returning EINTR) and "fast" calls which return
> immediately.  open() on a filesystem file is "fast" and is supposed to
> return immediately, but open on a named pipe is slow and may hang for
> an arbitrarily large time.  The Common Lisp OPEN function is not
> appropriate for such files, at least not in a multiprocessing image.
> I don't think this is particularly a Lisp problem, in that I can't
> think of any way even in C to wait for a named pipe to be in a state
> that wouldn't block, other than using polling.

Under SunOS 4.1.1 one can specify an O_NDELAY option to "open".  Then,
if the open is for reading, the call will return immediately with a
file descriptor (which can then be fed to "select").  For writing to a
named pipe with O_NDELAY set "open" returns an error (ENXIO).
Personally, I find the second behavior obnoxious... the behavior of
"connect" seems better.

Anyway, the following would work reasonably well as an implementation
of the Common Lisp "open" command:

(1) Do an "open" with O_NDELAY specified.
(2) If the open succeeds, you win.
(3) If the open fails with ENXIO:
(3a) Stat the file... if it is not a named pipe, return a failure.
(3b) Otherwise, either start a polling loop or (better) fork off a
subprocess to do the open and have it return the file descriptor using
unix domain IPC over a pipe.

The nice thing about the unix domain IPC approach is that you only pay
the price when necessary, and the descriptor that you finally end up
with is a "real" descriptor.

In my opinion, the whole I/O system should be written to use
non-blocking I/O.  On the other hand, a standard unix threads package
with MT safe library calls should be available pretty soon and would
make things a lot easier for implementors.


-- Jim Mayer
                                        Phone: (716) 422-9407
Webster Research Center                 Intelnet phone: 8*222-9407
Xerox Corporation                       Internet Email: mayer@wrc.xerox.com
800 Phillips Road, 0128-29E             XNS Email: James L Mayer:Wbst128:xerox
Webster, New York 14580                 Facsimile: (716) 265-7133