[comp.lang.rexx] anomalous AREXX behaviour

vansickl@bcrka340.bnr.ca (Greg VanSickle 1561848) (04/09/91)

While showing rexx to a freind I typed in the simple programme given
in AC's Tech Amiga article on Interprocess Communication.
It didn't work! The source for the two programmes are given below -
note the two trace statements marked as T1 and T2, the symptoms
depended heavily on them. Simple1 runs simple2, sends it 25 messages,
then quits. Simple2 opens a port, waits for 25 messages, displays them,
closes the port and quits:


/* simple1.rexx */
                
trace r                                       <---- T1
address command
call addlib("rexxsupport.library",0, -30, 0)
run rx simple2
call delay(300)
address PORT
do i = 1 to 50 by 2
   i i i
end
exit



/* simple2.rexx */

trace r                                       <---- T2
call openport(PORT)
call delay(500)
do i = 1 to 50 by 2
   call waitpkt(PORT)
   pkt = getpkt(PORT)
   say getarg(pkt)
   call reply(pkt)
end
call closeport(PORT)
exit


If T1 isn't included, and T2 is, then the program runs to
completion as expected. However, if T2 is not included then
I get the following sent to the consol:

      1 1 1
      3 3 3
      5 5 5
      7 7 7

      Error 18 in line 8: Invalid argument to funtion
      +++ command returned 10

      Command returned 10/18: Invalid argument to function
      +++ Error 13 in line 9: Host Environment not found

      bin:rexx/rx faiiled (return code 10)


If T1 is included and T2 is not then I get a similar result
but it fails on the first message, not the 5th.

Question 1:  'address PORT'  ... 'i i i' must build a packet and send
             it to the port PORT. Does the programme continue past
             the statement  'i i i' before the reply message is received?

Question 2:  I noticed that it's difficult to keep consol output separate
             when two rexx programmes are running. Does anyone know an easy
             way to keep the output from simple1 and simple2 separate ?

Question 3:  I make the following (but shakey) conclusion, is it correct?

             Between waitpkt and getpck in simple2, simple1 terminates,
             which means the reply port disappears, hence PORT is no
             longer a valid argument for getpkt. This implies the answer
             to question 1 is 'yes', ie. all 25 messages are sent regardless
             of the status of replies to any of them. If this is the case,
             the programme is fundamentally flawed.

Question 4:  How do you make this work?


Thanks in advance.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Geg VanSickle                                Silicon Support
                                                
Bell Northern Research                       phone: 613-763-5160                            
PO Box 3500                                  ESN: 393-5160
Nepean, Ontario, Canada                      
K2H 8V4                                      cocos: Greg Van Sickle
                                             email: vansickl@bnr.ca
---------------------------------------------------------------------
Vancouver van cu' ver  n.   where we should all be, as opposed to
                            where I am  
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

WGLP09@SLACVM.SLAC.STANFORD.EDU (04/11/91)

There are so many things wrong with your T1 and T2 that I won't even
begin to try to answer them all. But for starters, the run rx simple2
(or whatever it was called) is asynchronous and the first messages
likely aren't sent because PORT doesn't exist yet. Secondly, there
may be multiple messages waiting on the port. After the WaitPkt, you
must loop over them with GetPkt until you get a NULL packet (c2d(0)
I seem to remember, or if you have a recent update, the null() function
return the kind of NULL you want). Only *then* should you waitpkt
again. Try some variations on this to get it to work... You may want
to use "WaitForPort" (a program that comes with ARexx) or a loop with
a delay to check that "PORT" finally exists before sending it messages.
And you need to have some way of telling the second program you're done
and that it should exit.
     Hope this helps for starters...

     Willy.
----------
Willy Langeveld - Bitnet: WGLP09 @ SLACVM - BIX: langeveld