home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
fish
/
devs&handlers
/
fifodev_448
/
fifo.doc
< prev
next >
Wrap
Text File
|
1991-02-01
|
9KB
|
226 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
r open for read
w open for write
rw open for read & write (full duplex)
c open in cooked mode - must be specified on one side only,
usually the slave side. Any data received by the slave
side is cooked before continuing on to the slave. This allows
the slave side, usually a shell and/or program, to change
between cooked and raw mode with the standard SCREEN_MODE
packet.
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 side (else slave). For example, the master
side writer "mw" is paired with the slave side reader "r":
mw -> r
mr <- w
mrw <-> rw
t tee read. Usually specified "rt" or "mrt" depending on what
you want to monitor. This option causes the read stream to
be a copy of available read data such that it does NOT
interfere with other readers.
Otherwise this fifo will compete with other fifos for read
data. For a remote shell, tee operation is not desireable
as a default but is useful to monitor the shell from an
independant program.
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 and is generally required to be specified for the slave
side of a shell (i.e. newshell fifo:name/rwkecs)
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)
You can send one or more signal to all the slaves (or masters
if 'm' is also included) using these flags. note that it is
not necessary to open a file handle to so, specifying a
string like this:
"FIFO:fubar/C"
would result in sending a ^C to all fubar slaves even though
the Open() fails due to the lack of a 'r' or 'w' in the
specification.
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. Openning a FIFO: for only one direction ('r' *or* 'w')
results in a half duplex connection. It is important to properly
specify the rw modes for the fifo.
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
Generally the shell is run off the slave side and the controlling
program is run off the master side. The side that runs the shell
MUST specify the 's' option, as shown above. Here is a description
of the flags used in the NewShell line:
rw full duplex connection. shell 'reads' from the master and
'writes' results back to the msater.
k if slave side is started up first, as in the above example, any
writes it does will NOT be lost. Not really required since the
slave side shell does not endcli itself.
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. (you can't in the above
example since the master is the 'remcli' program.
note that in COOKED mode, FIFO: echo's characters received on
the slave side back to the master, just like the console
device.
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> copy FIFO:name/rmt t:capture
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. The RemCLI program uses the fifo.library
to access the master side and thus TEEs automatically.
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 if the writer is still writing, the writer will
freeze up when the fifo becomes full (requiring a reader to unfreeze
it). Additionally, if the 'k' option is not used, even if the writer
does not freeze up there may be unwanted data left in the fifo even
though nobody is referencing it.
1> cat <FIFO:xx/r
2> cat >FIFO:xx/wme
To safely recover from a broken reader, the program controlling the
pipe must do the following steps:
(1) break the writer if it has not exited (but it may be frozen,
so...)
(2) open a reader /r and a writer /wme, then immediately close
the writer.
(3) read from the reader until EOF. Even if the original writer
had already exited, the fact that you open and close a dummy
one will regenerate the EOF.