FORTRAN Reference Manual

Interprocess Communication
FORTRAN Reference Manual528615-001
14-18
Message Queuing
If a request for the current record has not been received, the server must continue to
read incoming requests until it finds one. This is done in an inner loop starting at
statement label 20 (line 48).
At line 49, the server reads a message from $RECEIVE. The LENGTH specifier
obtains the number of bytes actually read; the SOURCE specifier obtains information,
in the 16-word array SOURCE, that identifies the requester. Lines 15 through 21
specify the layout of the SOURCE array for programs compiled with ENV OLD in effect
or programs that do not specify an ENV directive. Lines 24 through 30 specify the
layout of the SOURCE array for programs compiled with ENV COMMON in effect. If
you specify ENV OLD for your program or you do not specify an ENV directive, you do
not need to specify toggle 1. FORTRAN compile-time toggles are FALSE by default. If
you specify ENV COMMON for a program unit, you must set compile-time toggle 1 with
a SETTOG directive in order to have the correct layout of the SOURCE array.
The server handles system messages read from $RECEIVE in lines 51 through 58. If
the server receives an OPEN message and the opener has specified a nowait depth
greater than 1, the server replies with file system error code 28; otherwise, it replies
with zero. The WRITE statement at line 56 sends a null reply to the message identified
by the MSGNUM specifier; the sender receives the value of the REPLY specifier as the
file system error code for the operation. Control then returns to the beginning of the
inner loop to read another message from $RECEIVE.
If the current message is not a system message, the server determines if it is a request
for the current data record. The MATCHNEW function invoked at line 60 accomplishes
this. If the message is a request for the current record, the server sends the record to
the requester. It then returns control to the beginning of the main loop to read another
data record.
If the current message is a request, but not for the current record, the server must save
the request in its list of pending requests until the specified record is read; this is
accomplished at lines 64 through 69. The server then returns control to the beginning
of the inner loop to read another incoming message.
38 10 CONTINUE
39 READ (UNIT=7,FMT=11,END=60) record(1), record(2)
40 11 FORMAT (2I5)
41 rqr = matchold (record, dest, dest this rqr, no rqr)
42 IF (rqr .NE. 0) THEN
43 messno(rqr) = -1
44 dest this rqr(rqr) = 0
45 WRITE (UNIT=6, msgnum=messno(rqr)) record
46 GO TO 10
47 END IF
Example 14-2. Example Queued Server (Part 1 of 3)