--
--	pingdemo.occ - execute program (ping localhost) for 5 seconds then kill it
--	Copyright (C) 2000-2008 Fred Barnes <frmb@kent.ac.uk>
--      Modifications (C) 2008 Tom Carlson
--
--	This program is free software; you can redistribute it and/or modify
--	it under the terms of the GNU General Public License as published by
--	the Free Software Foundation; either version 2 of the License, or
--	(at your option) any later version.
--
--	This program 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 General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program; if not, write to the Free Software
--	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--

#INCLUDE "proc.module"

PROC pingdemo (CHAN BYTE kyb?, scr!, err!)
  [2][9]BYTE command:
  INT result:
  [1]ENVIRONMENT env:
  SEQ
    --{{{  setup command
    SEQ i = 0 FOR (SIZE command)
      SEQ j = 0 FOR (SIZE command[i])
        command[i][j] := (BYTE #00)
    [command[0] FOR 4] := "ping"
    [command[1] FOR 9] := "localhost"
    --}}}  
    CHAN BOOL kill.chan:
    CHAN INT result.chan:
    PAR
      --{{{  blocking call (run ping)
      proc.altable.wrapper (kill.chan?, result.chan!, [env FOR 0], command, kyb?, scr!, err!, result!)
      --}}}  
      --{{{  catch completion or timeout
      TIMER tim:
      INT time:
      SEQ
        tim ? time
        time := (time PLUS 4200000)
        PRI ALT
          --{{{  call finished
          INT any:
          result.chan ? any
            kill.chan ! TRUE
          --}}}  
          --{{{  timeout
          tim ? AFTER time
            PAR
              kill.chan ! TRUE
              INT any:
              result.chan ? any
          --}}}  
      --}}}  
:

