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