home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / util / misc / fifolib38_1.lha / fifo.doc < prev    next >
Text File  |  1995-12-20  |  12KB  |  313 lines

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