Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 25
Receiving Messages in the Backup Process
Once the backup process is open, the primary process can communicate with the
backup process by writing messages to the file number returned by the FILE_OPEN_
call. To send a message, the primary process can use either WRITE[X] (for one-way
communication only) or WRITEREAD[X] (for one-way or two-way communication).
The following example sends a state message to the backup process without
expecting a reply:
{
...
error = WRITEX (backup_filenum, /*file number of backup*/
msg_buffer, /*Buffer containing state info*/
length, /*length of state info*/
count_written); /*number of bytes read by
backup*/
...
}
Receiving Messages in the Backup Process
To receive messages from the primary process or the system, the backup process first
opens the $RECEIVE file, then reads messages from it. For two-way communication,
in which the backup process replies to the primary process, set the receive-depth
parameter of the FILE_OPEN_ procedure to a value greater than zero. For one-way
communication, in which the backup process does not reply to the primary process, set
the receive-depth parameter to zero.
The first word of a system message is always a negative message number. The
primary process can insert a positive number in the first word of a state information
message, thereby giving the backup process a means of distinguishing between
system messages and state information messages.
The following example opens and reads from $RECEIVE for one-way communication.
The program tests the first word of the message to determine whether it is a system
message or a state information message:
/*Open $RECEIVE*/
filename = "$RECEIVE";
length = 8;
error = FILE_OPEN_(filename, /*the $RECEIVE file*/
length, /*length of filename*/
&filenum, /*file number returned*/
/*access*/
/*exclusion*/
/*nowait*/
/*receive_depth*/);
/*Read and process message*/
err = READX (filenum, /*file number of $RECEIVE file*/
msg_buffer, /*message returned*/
count_read, /*bytes read*/);
/*Process message based on message number*/