Guardian Programmer's Guide

Table Of Contents
Communicating With Processes
Guardian Programmer’s Guide 421922-014
6 - 6
Writing Messages to Another Process
Writing Messages to Another Process
Once the process file is open, you can communicate with the process by writing a
message to the file number returned by the FILE_OPEN_ call. To send a message,
you use either the WRITE[X] or WRITEREAD[X] procedure. For two-way
communication (reply data expected), you should use WRITEREAD[X]. For one-way
communication (no reply data expected) or one-way communication with error return,
you can use a call to WRITE[X] or WRITEREAD[X].
As mentioned earlier under Opening a Process, the requester can open the server
process for waited or nowait I/O. If the requester can wait for a reply, it should use
waited I/O. If the requester cannot wait, it should initiate communication using nowait
I/O and complete the communication later with a call to the AWAITIO[X] procedure.
This is an application design issue. Refer to Section 4, Using Nowait Input/Output, for
a detailed discussion of nowait I/O.
Writing a Message: No Reply Data Expected
The following example writes a message to a process without expecting any reply
data. Here, the process has been opened using waited I/O.
LENGTH := $LEN(REQUEST.MESSAGE);
SBUFFER ':=' REQUEST.MESSAGE FOR LENGTH;
CALL WRITEX(PROC^NUM,
SBUFFER,
LENGTH,
COUNT^WRITTEN);
IF <> THEN ...
The WRITEX procedure returns when the recipient process has read the message by
issuing a READ[X] procedure call or has called REPLY[X] to respond to the message
after having read it with READUPDATE[X]; that is, the sender and recipient processes
remain synchronized. The count-written parameter shows how many bytes were
read by the recipient process.
If you use WRITEREAD[X] to send a one-way message, then that call also returns as
soon as the recipient process issues a READ[X] procedure call (or a READUPDATE[X]
procedure call followed by a REPLY[X] call). In this case, the WRITEREAD[X]
procedure returns no bytes.
If you opened the process using nowait I/O, then the WRITE[X] procedure returns
immediately. The requester and server become synchronized when the requester
completes the corresponding call to AWAITIO[X]. The following example shows how
this part of the requester might be coded:
LENGTH := $LEN(REQUEST.MESSAGE);
SBUFFER ':=' REQUEST.MESSAGE FOR LENGTH;
CALL WRITEX(PROC^NUM,
SBUFFER,
LENGTH,
COUNT^WRITTEN);
IF <> THEN ...