home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
devs&handlers
/
fifodev_432
/
fifo.doc
< prev
next >
Wrap
Text File
|
1991-01-12
|
7KB
|
183 lines
FIFO.DOC
(c) Copyright 1990, Matthew Dillon, All Rights Reserved
BIX: mdillon
UUCP: dillon@overload.Berkeley.CA.US
FIFO:
FIFO: is like PIPE: but is based on fifo.library rather than its
own implementation. Full master/slave support exists. Since
FIFO: uses fifo.library, programs that require non-blocking IO
capability can access one side of a FIFO: connection via the
fifo.library instead of FIFO:
The implementation of FIFO: and fifo.library is a billion times
better than that for PIPE:
FIFO:<name>/<flags>
<name>: a valid fifo name
name may be any combination of alpha numerics up to 64 chars long,
and is case sensitive. FIFO: will append either "_m" or "_s" to
the name it supplies to fifo.library depending on whether master
mode or slave mode is selected.
<flags>: a valid combination of flags
note that the combination "rw" is perfectly valid and provides
a full duplex connection pair between a master and a slave.
r open for read
w open for write
c open in cooked mode - FIFO: handles cooked data processing
of any writes done by the master side. Additionally, FIFO:
echos data written to a master back to the master.
e EOF mode (when combined with 'w'). When this file handle
is closed, an EOF will be sent to the other side.
k KEEP mode. If a writer opens a fifo, writes data, then
closes the fifo before a reader has a chance to open the
fifo, this flag prevents the data from being lost.
m select master (else slave). See below
t tee read (this fifo gets an independant read stream for
monitoring purposes and does NOT interfere with other readers)
Otherwise this fifo will compete with other fifos for read
data.
s SHELL mode, creates a separate message port for the handle
allowing the shell & progams to find their STDERR handle.
(i.e. the open-* packet works properly)
WARNING: use of this option increases overhead in the FIFO:
device, use only for remote-shell applications.
C Send ^C to all (slaves or masters)
D Send ^D to all (slaves or masters)
E Send ^E to all (slaves or masters)
F Send ^F to all (slaves or masters)
NOTE: something like "FIFO:fubar/C" is valid even though the
Open() will fail because no 'r' or 'w' options were specified.
The ^C (in this example) would be sent properly to all slaves.
SEE REMCLI.C FOR EXAMPLE IMPLEMENTATION
LINKED FIFOS
FIFO: provides a full duplex connection using TWO fifo.library FIFOS.
Openning a fifo in master mode verses slave mode determines which
names are used for reading and writing. You should note that when
a FIFO: handle is openned for both read and write, reading from the
handle actually accesses a different physical fifo than writing to
the handle.
FIFO: device fifo.library
Open("FIFO:junk/w", 1005); junk_s
Open("FIFO:junk/r", 1005); junk_m
Open("FIFO:junk/rw",1005); junk_s (w), junk_m (r)
Open("FIFO:junk/wm", 1005); junk_m
Open("FIFO:junk/rm", 1005); junk_s
Open("FIFO:junk/rwm", 1005); junk_m (w), junk_s (r)
REMOTE SHELL
It is extremely easy to set up a fifo to interface a program with a
remote shell. The FIFO: fully supports remote shells including
the ability to propogate ^C through ^F and handle stderr.
Not only that, but programs which need to be able to access the
master side of a shell in a non-blocking fashion may access the
master side directly through FIFO.LIBRARY calls. See FIFOLIB.DOC
for the function call list, see REMCLI.C for a working example.
1> NewShell FIFO:name/rwkecs
1> run remcli name
NOTES FOR SLAVE SIDE:
r shell must be able to read the handle
w shell must be able to write the handle
k if slave side is started up first, any writes it does will
NOT be lost.
e when slave side closes the handle, an EOF will be sent to
the master side.
c run slave side in COOKED mode. FIFO: will do command line
editing on any data sent to the slave side. You do not specify
COOKED mode for the master side. I repeat, do NOT specify
cooked mode for the master side.
s SHELL support, required on the slave specification when run
from NewShell, causes the handle to get its own message port.
(required to support Open("*", ...);
NOTE: YOU CAN RUN 'remcli name' MULTIPLE TIMES SIMULTANIOUSLY
USING THE SAME FIFO NAME. All remcli's talking to the same
shell will get all output from the shell and additionally be
able to issue commands. This can be extremely useful as a
monitoring tool.
1> run remcli name
1> run remcli name
You can also capture all shell interaction with this:
1> cat FIFO:name/rt
The 't' (TEE) specification is required to ensure you
do not screw up any other readers. There is no limit on the
number of 'readers' monitoring a named fifo.
If RemCLI tries to talk to a fifo that does not exist,
it will 'freeze' until the slave side does exist. Meaning you
can run RemCLI before you start up the shell.
CLOSING THE REMCLI WINDOW DOES NOT END THE SHELL. You must type
'endcli' or 'endshell' to cause it to exit. On the otherhand,
closing the remcli window and then reopenning will yield the
previous shell (which never exited).
PIPEING
You can use the FIFO: device to pipe output from one program to the
input of another. Note that you want to be sure to use the 'k' flag
in case the program generating the output generates only a little (and
is able to exit before you have a chance to start the reader). You
also want to use the 'e' (EOF) option or the reader will not receive
an EOF, and you must make one side a master.
1> cat >FIFO:xx/wkme
1> cat <FIFO:xx/r
If you do not specify the 'e' EOF option then you can run multiple
program's output through the pipe sequentially, specifying the eof
option only for the last one.
WARNING: If you ^C the reader before it gets the EOF and exits
on its own, and the 'k' option is used, the named fifo will still
exist with the left over data in it. This can be fixed by either
draining the data or by running the reader first, and writer second
and NOT using the 'k' option:
1> cat <FIFO:xx/r
2> cat >FIFO:xx/wme
In the above case the reader can be safely ^C'd without any left over
junk in the fifo (assuming the writer exits).