[comp.sys.amiga.programmer] Waiting for a port in AREXX...

skank@iastate.edu (Skank George L) (02/16/91)

     Hello folks, I'm writing an Arexx program and I'd like to wait for another
port to appear before the program proceeds.  How do you do this in Arexx,  all
I can find is WaitForPort.  What I'd like is an equivalent Arexx command or
procedure, that is, a command or procedure that will pause the execution of
the script until the port appears.  What would be better is one that would wait
for a minute or two then time out if it can't find it.  Additionally, is there
a command that will suspend execution of the current Arexx program for X amount
of time, like a pause() or sleep() or wait() function?  Any help appreciated.
				Thanks,
					--George

--

George L. Skank			|
skank@iastate.edu		|Fast cars, fast women, fast computers...
Senior, Electrical Engineering	|Not necessarily in that order

higgin@cbmvax.commodore.com (Paul Higginbottom - CATS) (02/18/91)

In article <1991Feb16.073956.24406@news.iastate.edu> skank@iastate.edu (Skank George L) writes:
$     Hello folks, I'm writing an Arexx program and I'd like to wait for another
$port to appear before the program proceeds.  How do you do this in Arexx,  all
$I can find is WaitForPort.  What I'd like is an equivalent Arexx command or
$procedure, that is, a command or procedure that will pause the execution of
$the script until the port appears.  What would be better is one that would wait
$for a minute or two then time out if it can't find it.  Additionally, is there
$a command that will suspend execution of the current Arexx program for X amount
$of time, like a pause() or sleep() or wait() function?  Any help appreciated.
$				Thanks,
$					--George
$

This should do the job...

/* wait around for a specific port
 * timeout after 60 seconds...
 *
 * Usage:
 *     call waitportexists 'YOURPORT'
 */

parse arg matchport

portfound = 0

do i = 1 to 6
	ports = show('p')			/* get port list */
	do until port=''
		parse var ports port ports	/* snap port off front of list */
		/* say 'Matching 'port' and 'matchport'...'*/
		if port=matchport then do
			portfound = 1
			leave i
			end
		end
	address command 'wait' 10
	end

return portfound

---------
/* testport.rexx
 * Try from command line, e.g:
 * 1> testport foo
 */

parse arg port

options results
say 'Waiting for 'port' to exist...'
call waitportexists port
x = result
if x~= 0 then say "it exists!"
else say "it doesn't exist"

jsivier@ux1.cso.uiuc.edu (Jonathon Sivier ) (02/19/91)

skank@iastate.edu (Skank George L) writes:

>     Hello folks, I'm writing an Arexx program and I'd like to wait for another
>port to appear before the program proceeds.  How do you do this in Arexx,  all
>I can find is WaitForPort.  What I'd like is an equivalent Arexx command or
>procedure, that is, a command or procedure that will pause the execution of
>the script until the port appears.  What would be better is one that would wait
>for a minute or two then time out if it can't find it.  Additionally, is there
>a command that will suspend execution of the current Arexx program for X amount
>of time, like a pause() or sleep() or wait() function?  Any help appreciated.
>				Thanks,
>					--George

I don't have my manual handy but I thought WaitForPort() did what you want.
As for a Wait routine, what I have done is call the AmigaDOS wait command.
i.e.
address command 'wait 10'	/* a 10 second wait */

Do this in a loop checking for a particular condition (existence of a port,
another program finishing, etc.) every 5 or 10 seconds.  After a specific
number of loops (1 or 2 minutes worth) exit the loop and time out.

I hope this gives you some ideas.

Jonathan

-------------------------------------------------------------------
|  Jonathan Sivier               |  Ballo ergo sum.               |
|  jsivier@ux1.cso.uiuc.edu      |  (I dance therefore I am.)     |
|  Flight Simulation Lab         |	        - des Cartwright  |
|  Beckman Institute             |                                |
|  405 N. Mathews                |                                |
|  Urbana, IL  61801             |                                |
-------------------------------------------------------------------

mwm@pa.dec.com (Mike (My Watch Has Windows) Meyer) (02/19/91)

In article <1991Feb16.073956.24406@news.iastate.edu> skank@iastate.edu (Skank George L) writes:

	Hello folks, I'm writing an Arexx program and I'd like to wait for
   another port to appear before the program proceeds.  How do you do this in
   Arexx,  all I can find is WaitForPort.  What I'd like is an equivalent
   Arexx command or procedure, that is, a command or procedure that will pause
   the execution of the script until the port appears.  What would be better
   is one that would wait for a minute or two then time out if it can't find
   it.

From the manual on WaitForPort, "This is the preferred way to pause
while a new ARexx host (or RexxMast) is started. It wait's for 10
seconds (as opposed to the minute or two you asked for), and then
exits with an rc of 5 if the port wasn't found. I normally use it like
this:

	if ~show(ports, 'AppPort') then address command 'run application'
	/ * do any setup I need to do here */
	address command 'waitforport AppPort'
	if rc > 0 then do
		"notify-user Can't start application"
		exit
		end
	/* and we're done */

If you really want to wait a minute (instead of the 10 seconds that
the WaitForPort Command does), call it repeatedly, like so:

	do 6 until rc = 0
		address command 'waitforport AppPort'
	if rc > 0 then do
		"notify-user Can't start application"
		exit
		end

You could check the port list yourself and delay, but the above will
exit as soon as the port becomes available, instead of at the end of
the delay during which the port appears.

  Additionally, is there a command that will suspend execution of the current
  Arexx program for X amount of time, like a pause() or sleep() or wait()
  function?  Any help appreciated.

Delay() is a direct link to the system Delay() function, taking a
single argument of the number of ticks (50ths of a second) to wait.
Note that 1.3 Delay() has a nasty bug if you call it with a tick count
of 0, so you should avoid that case.

	<mike
--
And then I saw her...					Mike Meyer
She was a bright red '64 GTO				mwm@pa.dec.com
With fins and gills like some giant piranha fish,	decwrl!mwm
Some obscene phallic symbol on wheels.