Guardian Programmer's Guide

Table Of Contents
Writing a Server Program
Guardian Programmer’s Guide 421922-014
22 - 5
Adding a Requester to the Opener Table
information about the message. Words 6 through 15 of the returned information
contain the process handle of the message sender; word 3 contains the file number:
CALL FILE_GETRECEIVEINFO_(RECEIVE^INFO);
PROCESS^HANDLE ':=' RECEIVE^INFO[6] for 10;
FILE^NUMBER := RECEIVE^INFO[3];
Adding a Requester to the Opener Table
If the message received on $RECEIVE is an Open message (system message -103),
then your program must try to add the requester to the opener table. First, you must
scan the table, looking for a blank entry; then you can write the process handle into
that space.
If the table is full, then you should reject the open attempt by returning error 12 to the
requester process.
The following code attempts to add a process handle to the opener table. It assumes
that a blank entry in the opener table contains -1 in each word.
!For an Open message (using literal from ZSYSTAL file):
IF BUFFER[0] = ZSYS^VAL^SMSG^OPEN THEN
BEGIN
!Return "file in use" error if opener table is full:
ERROR^NUMBER := 12;
!Put the process ID into the opener table at the first
!empty location and increment the count of openers. Note
!that you need check only the first word of the process
!handle entry in the table; if it is -1, then the entry is
!empty:
I := 1;
DONE := 0;
WHILE I <= MAX^OPENERS AND DONE = 0 DO
BEGIN
IF OPENER^TABLE[I].PROCESS^HANDLE[0] = -1 THEN
BEGIN
OPENER^TABLE[I].PROCESS^HANDLE[0] ':='
CALLING^PROCESS^PID FOR 10 WORDS;
OPENER^TABLE[I].FILE^NUMBER := CALLING^PROCESS^FNUM;
NUMBER^OF^OPENERS :=
NUMBER^OF^OPENERS + 1;
ERROR^NUMBER := 0;
DONE := -1;
END;
I := I + 1;
END;
WCOUNT := 0;
CALL REPLY(BUFFER,
WCOUNT,
!count^written!,
!message^tag!,