--
--	Inmos Libraries
--	Copyright (C) 1988, 1989, 1990, 1991, 1993  Inmos Limited
--
--	This library is free software; you can redistribute it and/or
--	modify it under the terms of the GNU Lesser General Public
--	License as published by the Free Software Foundation; either
--	version 2 of the License, or (at your option) any later version.
--
--	This library is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	Lesser General Public License for more details.
--
--	You should have received a copy of the GNU Lesser General Public
--	License along with this library; if not, write to the Free Software
--	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
--

--** @module hostio


#COMMENT "Host i/o library, V1.00, 10/03/89"
#COMMENT "(c) Copyright INMOS Limited 1989"
#INCLUDE "hostio.inc"
--{{{  sp.buffer
--* Act as a communication buffer.
--
-- No more than sp.max.packet.data.size bytes can be buffered. Primary
-- input to this routine must be on the guard input channels from.user
-- or stopper. Input on from.user is stored, output on ts, then a reply
-- is expected on fs; this reply is stored and then output on to.user,
-- and all this must finish before any new input can be received on
-- from.user or stopper.
--
-- @param fs input to this routine
-- @param ts output from this routine
-- @param from.user input to this routine
-- @param to.user output from this routine
-- @param stopper input to this routine; TRUE or FALSE received will
--   terminate this routine
PROC sp.buffer (CHAN OF SP fs, ts, from.user, to.user, CHAN OF BOOL stopper)
  --{{{  more info
  --           Due to the fact that a reply is expected on the fs channel once
  --           something has been sent on the ts channel, this routine is
  --           primarily intended to go inbetween some process and the iserver,
  --           where the process is the originator of data governing the ensuing
  --           action of this routine.
  --           The channels fs and ts need not go directly to the server, but
  --           could go to another SP protocol process, eg another buffer or
  --           a multiplexor.
  --}}}  

  [sp.max.packet.data.size]BYTE buffer :
  INT16 len :
  BOOL  running :
  SEQ
    running := TRUE
    WHILE running
      ALT
        from.user   ? len :: buffer
          SEQ
            ts      ! len :: buffer
            fs      ? len :: buffer
            to.user ! len :: buffer
        stopper ? running
          running := FALSE
:
--}}}  sp.buffer
--{{{  so.buffer
PROC so.buffer (CHAN OF SP fs, ts, from.user, to.user, CHAN OF BOOL stopper)

  sp.buffer (fs, ts, from.user, to.user, stopper)
:
--}}}  so.buffer
