home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d519 / fifolib.lha / FifoLib / fifo.doc < prev    next >
Text File  |  1991-07-22  |  11KB  |  287 lines

  1.  
  2.                 FIFO.DOC
  3.  
  4.          (c) Copyright 1990, Matthew Dillon, All Rights Reserved
  5.  
  6.             BIX:    mdillon
  7.             UUCP:    dillon@overload.Berkeley.CA.US
  8.  
  9.  
  10.     (1) INSTALLATION
  11.  
  12.     To Install the system you must install both FIFO-HANDLER and
  13.     FIFO.LIBRARY.
  14.  
  15.     1> lharc -r -x -a x fifo3.lzh
  16.     1> cd fifolib
  17.     1> Copy l/fifo-handler l:
  18.     1> Copy libs/fifo.library libs:
  19.  
  20.     THERE IS NO MOUNTLIST OR MOUNT FOR FIFO: ... To start the handler
  21.     and make FIFO: available to programs, you must RUN it from your
  22.     startup-sequence.  Generally the easiest way to do this is to
  23.     include the following line:
  24.  
  25.     run <nil: >nil: l:fifo-handler
  26.  
  27.     IF YOU HAVE A FIFO: ENTRY IN YOUR MOUNTLIST, PLEASE DELETE IT TO
  28.     PREVENT ACCIDENTLY TRYING TO MOUNT IT.
  29.  
  30.     (2) SIMPLE EXAMPLE TO GET YOU STARTED
  31.  
  32.     This is a simple example to get you started.  Please refer to
  33.     section (3) below for a description of the options.
  34.  
  35.     1> run type s:startup-sequence >fifo:wmke
  36.     1> type fifo:r
  37.  
  38.     (3) USAGE FOR FIFO:
  39.  
  40.     FIFO: is like PIPE: but is based on fifo.library rather than its
  41.     own implementation.  Full master/slave support exists.    Since FIFO:
  42.     uses fifo.library, programs that require non-blocking IO capability
  43.     can access one side of a FIFO: connection via the fifo.library
  44.     instead of FIFO:
  45.  
  46.     The implementation of FIFO: and fifo.library is a billion times
  47.     better than that for my original PIPE: handler.
  48.  
  49.     The primary difference with FIFO: is that it is based on a
  50.     MASTER-SLAVE connection.  Two MASTER-SLAVE connections going in
  51.     opposite directions yields a full-duplex connection.  When using
  52.     FIFO: to direct one program's output to another's input you must
  53.     explicitly specify one of the FIFO:'s to be the master and the
  54.     other the slave, as well as specify read & write flags.  The
  55.     general format for accessing the FIFO: handler is as follows:
  56.  
  57.         FIFO:<name>/<flags>
  58.  
  59.     <name>:    a valid fifo name
  60.  
  61.     name may be any combination of alpha numerics up to 64 chars long,
  62.     and is case sensitive.    FIFO: will append either "_m" or "_s" to
  63.     the name it supplies to fifo.library depending on whether master
  64.     mode or slave mode is selected.
  65.  
  66.     <flags>:    a valid combination of flags
  67.  
  68.     r   open for read.  Allows you to read from this fifo.
  69.  
  70.     w   open for write.  Allows you to write to this fifo
  71.  
  72.     rw  open for read & write (full duplex).  This opens a
  73.         full duplex connection, generally useful only in
  74.         remote-shell applications.
  75.  
  76.     c   open in cooked mode - must be specified on one side only,
  77.         usually the slave side.  Any data received by the slave
  78.         side is cooked before continuing on to the slave.  This allows
  79.         the slave side, usually a shell and/or program, to change
  80.         between cooked and raw mode with the standard SCREEN_MODE
  81.         packet.
  82.  
  83.     e   EOF mode (when combined with 'w').  When this file handle
  84.         is closed, an EOF will be sent to the other side.
  85.  
  86.         If not specified, you can cause several programs to 'append'
  87.         their output onto a single FIFO all of which is read by a
  88.         single program.  This can be useful in log-recorder
  89.         applications, for example.
  90.  
  91.         Specifying the 'e' flag generates an EOF after the last byte
  92.         of data is written to the FIFO and the writer closes it.  A
  93.         reader will read the data and then receive the EOF, generally
  94.         terminating reader operations.
  95.  
  96.     k   KEEP mode.    If a writer opens a fifo, writes data, then
  97.         closes the fifo before a reader has a chance to open the
  98.         fifo, this flag prevents the data from being lost.
  99.  
  100.         If not specified, the data will be lost.  Generally you
  101.         want to specify this flag.
  102.  
  103.     m   select master side (else slave).  For example, the master
  104.         side writer "mw" is paired with the slave side reader "r":
  105.  
  106.             mw   -> r
  107.             mr  <-    w
  108.             mrw <-> rw
  109.  
  110.         When operating a pipe where you have a writer into the fifo
  111.         and then a reader from the same fifo, one of the two must
  112.         be a MASTER, with the 'm' flag specified, and the other side
  113.         must be a SLAVE, with the 'm' flag NOT specified, as per
  114.         the example in section (2).
  115.  
  116.     t   tee read.  Usually specified "rt" or "mrt" depending on what
  117.         you want to monitor.  This option causes the read stream to
  118.         be a copy of available read data such that it does NOT
  119.         interfere with other readers.
  120.  
  121.         Otherwise this fifo will compete with other fifos for read
  122.         data.  For a remote shell, tee operation is not desireable
  123.         as a default but is useful to monitor the shell from an
  124.         independant program.
  125.  
  126.         see the REMCLI example below.
  127.  
  128.     s   SHELL mode, creates a separate message port for the handle,
  129.         allowing the shell & progams to find their STDERR handle.
  130.         (i.e. the open-* packet works properly).
  131.  
  132.         WARNING: use of this option increases overhead in the FIFO:
  133.         device and is generally required to be specified for the slave
  134.         side of a shell (i.e. newshell fifo:name/rwkecs)
  135.  
  136.         see the REMCLI example below.
  137.  
  138.     C   Send ^C to all (slaves or masters)
  139.     D   Send ^D to all (slaves or masters)
  140.     E   Send ^E to all (slaves or masters)
  141.     F   Send ^F to all (slaves or masters)
  142.  
  143.         You can send one or more signal to all the slaves (or masters
  144.         if 'm' is also included) using these flags.  note that it is
  145.         not necessary to open a file handle to so, specifying a
  146.         string like this:
  147.  
  148.         "FIFO:fubar/C"
  149.  
  150.         would result in sending a ^C to all fubar slaves even though
  151.         the Open() fails due to the lack of a 'r' or 'w' in the
  152.         specification.
  153.  
  154.              SEE REMCLI.C FOR EXAMPLE IMPLEMENTATION
  155.              OF COOKED MODE AND SIGNALS.
  156.  
  157.  
  158.     (4) TECHNICAL, INTERACTION BETWEEN FIFO: and FIFO.LIBRARY
  159.  
  160.                    LINKED FIFOS
  161.  
  162.     FIFO: provides a full duplex connection using TWO fifo.library FIFOS.
  163.     Openning a fifo in master mode verses slave mode determines which
  164.     names are used for reading and writing.  You should note that when
  165.     a FIFO: handle is openned for both read and write, reading from the
  166.     handle actually accesses a different physical fifo than writing to
  167.     the handle.  Openning a FIFO: for only one direction ('r' *or* 'w')
  168.     results in a half duplex connection.  It is important to properly
  169.     specify the rw modes for the fifo.
  170.  
  171.          FIFO: device             fifo.library
  172.  
  173.     Open("FIFO:junk/w", 1005);              junk_s
  174.     Open("FIFO:junk/r", 1005);              junk_m
  175.     Open("FIFO:junk/rw",1005);              junk_s (w), junk_m (r)
  176.  
  177.     Open("FIFO:junk/wm", 1005);             junk_m
  178.     Open("FIFO:junk/rm", 1005);             junk_s
  179.     Open("FIFO:junk/rwm", 1005);            junk_m (w), junk_s (r)
  180.  
  181.     (5) REMOTE SHELL APPLICATIONS
  182.  
  183.     It is extremely easy to set up a fifo to interface a program with a
  184.     remote shell.  The FIFO: fully supports remote shells including the
  185.     ability to propogate ^C through ^F and handle stderr ("*").
  186.  
  187.     Not only that, but programs which need to be able to access the
  188.     master side of a shell in a non-blocking fashion may access the
  189.     master side directly through FIFO.LIBRARY calls.  See FIFOLIB.DOC
  190.     for the function call list, see REMCLI.C for a working example.
  191.  
  192.     1> NewShell FIFO:name/rwkecs
  193.     1> run remcli name
  194.  
  195.     Generally the shell is run off the slave side and the controlling
  196.     program is run off the master side.  The side that runs the shell
  197.     MUST specify the 's' option, as shown above.  Here is a description
  198.     of the flags used in the NewShell line:
  199.  
  200.     rw  full duplex connection.  shell 'reads' from the master and
  201.         'writes' results back to the msater.
  202.  
  203.     k   if slave side is started up first, as in the above example, any
  204.         writes it does will NOT be lost.  Not really required since the
  205.         slave side shell does not endcli itself.
  206.  
  207.     e   when slave side closes the handle, an EOF will be sent to
  208.         the master side.
  209.  
  210.     c   run slave side in COOKED mode.  FIFO: will do command line
  211.         editing on any data sent to the slave side.  You do not specify
  212.         COOKED mode for the master side.  I repeat, do NOT specify
  213.         cooked mode for the master side.  (you can't in the above
  214.         example since the master is the 'remcli' program.
  215.  
  216.         note that in COOKED mode, FIFO: echo's characters received on
  217.         the slave side back to the master, just like the console
  218.         device.
  219.  
  220.     s   SHELL support, required on the slave specification when run
  221.         from NewShell, causes the handle to get its own message port.
  222.         (required to support Open("*", ...);
  223.  
  224.     NOTE:  YOU CAN RUN 'remcli name' MULTIPLE TIMES SIMULTANIOUSLY
  225.     USING THE SAME FIFO NAME.  All remcli's talking to the same shell
  226.     will get all output from the shell and additionally be able to
  227.     issue commands.  This can be extremely useful as a monitoring tool.
  228.  
  229.         1> run remcli name
  230.         1> run remcli name
  231.  
  232.     You can also capture all shell interaction with this:
  233.  
  234.         1> copy FIFO:name/rmt t:capture
  235.  
  236.     The 't' (TEE) specification is required to ensure you do not screw
  237.     up any other readers.  There is no limit on the number of 'readers'
  238.     monitoring a named fifo.  The RemCLI program uses the fifo.library
  239.     to access the master side and thus TEEs automatically.
  240.  
  241.     If RemCLI tries to talk to a fifo that does not exist, it will
  242.     'freeze' until the slave side does exist.  Meaning you can run
  243.     RemCLI before you start up the shell.
  244.  
  245.     CLOSING THE REMCLI WINDOW DOES NOT END THE SHELL.  You must type
  246.     'endcli' or 'endshell' to cause it to exit.  On the otherhand,
  247.     closing the remcli window and then reopenning will yield the
  248.     previous shell (which never exited).
  249.  
  250.  
  251.                 PIPEING
  252.  
  253.     You can use the FIFO: device to pipe output from one program to the
  254.     input of another.  Note that you want to be sure to use the 'k' flag
  255.     in case the program generating the output generates only a little (and
  256.     is able to exit before you have a chance to start the reader).  You
  257.     also want to use the 'e' (EOF) option or the reader will not receive
  258.     an EOF, and you must make one side a master.
  259.  
  260.     1> type s:startup-sequence >FIFO:xx/wkme
  261.     1> type FIFO:xx/r
  262.  
  263.     If you do not specify the 'e' EOF option then you can run multiple
  264.     program's output through the pipe sequentially, specifying the eof
  265.     option only for the last one.
  266.  
  267.     WARNING:    If you ^C the reader before it gets the EOF and exits
  268.     on its own, and if the writer is still writing, the writer will
  269.     freeze up when the fifo becomes full (requiring a reader to unfreeze
  270.     it).  Additionally, if the 'k' option is not used, even if the writer
  271.     does not freeze up there may be unwanted data left in the fifo even
  272.     though nobody is referencing it.
  273.  
  274.     To safely recover from a broken reader, the program controlling the
  275.     pipe must do the following steps:
  276.  
  277.     (1) break the writer if it has not exited (but it may be frozen,
  278.         so...)
  279.  
  280.     (2) open a reader /r and a writer /wme, then immediately close
  281.         the writer.
  282.  
  283.     (3) read from the reader until EOF.  Even if the original writer
  284.         had already exited, the fact that you open and close a dummy
  285.         one will regenerate the EOF.
  286.  
  287.