Open System Services Programmer's Guide

Example 47 Using $RECEIVE in an OSS Requester Process
/* requester1.c
*
* Simple OSS requester example using Guardian file input/output
* APIs for communication between requester and server.
*
* This requester accepts terminal input and sends it to a
* server using a waited WRITEREADX() call. When the server
* echoes the data back to the requester, the WRITEREADX() call
* completes and the requester prompts for more terminal input.
* When terminal input ends with EOF, the server is closed and
* the requester stops.
*/
#include <unistd.h>
#include <fcntl.h>
#include <tal.h>
#include <cextdecs.h(FILE_OPEN_,FILE_CLOSE_, \
WRITEREADX,FILE_GETINFO_)>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
short retcode; /* return code for APIs that return short */
_cc_status CC; /* return code for APIs that return condition code */
#define BUFF_LEN 1024 /* buffer length */
char msg_buff[BUFF_LEN+1]; /* buffer */
char *procname; /* pointer to server process name */
short fnum, bytesread, error;
int main(int argc, char **argv)
{
/* Get server process name from the command line,
else assign default name $ECHO. */
if (argc > 1)
procname = argv[1];
else
procname = "$ECHO";
printf("Requester starting\n");
/* Requester process opens the server process for waited IO. */
retcode = FILE_OPEN_(
procname, /* server process name */
(short)strlen(procname), /* process name length */
&fnum, /* file number returned */
0, /* access mode (r/w) */
0, /* exclusion mode (shared) */
0); /* nowait depth (waited IO)*/
if (retcode != 0) /* if error, exit(1) */
{
fprintf(stderr, "FILE_OPEN_() to %s failed\n", procname);
fprintf(stderr, "Return code = %d\n", retcode);
exit(1);
}
/* Prompt user, read data, send data to server and wait for reply */
while (1)
{
printf("?"); /* send prompt */
fgets(msg_buff, BUFF_LEN, stdin); /* read user input */
if (feof(stdin)) /* if EOF */
{
194 Interprocess Communication