[comp.sys.amiga.tech] Ports in Modula 2

lhotka@incstar.uucp (Glamdring) (09/07/90)

I am having a problem using ports in Modula 2...  I have the following program
which is an adaption of an example C program in the 'Programmer's Guide to the
Amiga' by Rob Peck.  The program gets into the first while loop waiting for a
NIL message pointer, but it always gets the same message back causing an
infinite loop.  Thanks for any help!!


MODULE T1;

FROM SYSTEM     IMPORT ADDRESS, ADR, BYTE;
FROM Tasks      IMPORT Wait, SignalSet;
FROM Ports      IMPORT GetMsg, MessagePtr, ReplyMsg, PutMsg, MsgPortPtr,
			Message, WaitPort;
FROM PortsUtil  IMPORT CreatePort, DeletePort;
FROM InOut      IMPORT WriteLn, WriteString;

VAR
	myPort  : MsgPortPtr;
	recPort : MsgPortPtr;
	mess    : Message;
	inmess  : MessagePtr;
        messadr : ADDRESS;
	instr   : POINTER TO ARRAY [1..100] OF CHAR;

BEGIN
  myPort := CreatePort(NIL,0);
  IF myPort # NIL THEN
    recPort := CreatePort(ADR("reply"),0);
    IF recPort # NIL THEN
      mess.mnNode.lnName := ADR("Hello world");
      mess.mnReplyPort := recPort;
      mess.mnLength := 0;
      messadr := ADR(mess);
      PutMsg(myPort^,ADR(mess));
      inmess := WaitPort(myPort^);
      WHILE inmess # NIL DO
	instr := inmess^.mnNode.lnName;
        WriteString("Message: ");
        WriteString(instr^);
        WriteLn;
        ReplyMsg(inmess);
        inmess := GetMsg(myPort^);
      END;
      inmess := WaitPort(recPort^);
      WHILE inmess # NIL DO
	instr := inmess^.mnNode.lnName;
        WriteString(instr^);
        WriteLn;
        inmess := GetMsg(recPort^);
      END;
      DeletePort(myPort^);
      DeletePort(recPort^);
    ELSE
      DeletePort(myPort^);
      WriteString("2nd create port failed");
      WriteLn;
    END;
  ELSE
    WriteString("1st create port failed");
    WriteLn;
  END;
END T1.

 ______________________________________________________________________
/ Rockford Lhotka				INCSTAR Corp	       \
| Systems Administrator				PO Box 285	       |
| incstar!lhotka@rosevax.rosemount.com		1990 Industrial Blvd   |
\ 612/779-1701					Stillwater, MN 55082   /
 ----------------------------------------------------------------------