Open System Services Programmer's Guide

Example 101 $RECEIVE Server
#define _PUT_MODEL_
#include <cextdecs.h(FILE_OPEN_)>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include myio.h /* contains my_fprintf which is process blocking */
short filenum;
void *
thread_start(void *parms)
{
long bytesread, error;
char buffer[2];
short receive_info[17];
while (1)
{
error = put_RECEIVEREAD(filenum, buffer,
(short)sizeof(buffer), &bytesread, -1,
receive_info, NULL);
if (error != 0) break;
/* Do real work here! */
error = put_REPLYX("server's reply.", 15, NULL,
receive_info[2], 0);
if (error != 0) break;
}
my_fprintf(stderr,"thread_start: error: %d\n",error);
return NULL;
}
int
main()
{
pthread_t thread1, thread2;
char *filename = "$RECEIVE";
if (FILE_OPEN_(filename, (short)strlen(filename), &filenum,
0, , 1, 2, 1) != 0)
{
my_fprintf(stderr,"main: FILE_OPEN_ failed.\n");
exit(1);
}
if (put_INITRECEIVE(filenum, 2) != 0)
{
my_fprintf(stderr,"main: put_INITRECEIVE failed\n");
exit(1);
}
if (pthread_create(&thread1, NULL, &thread_start, NULL) != 0)
{
perror("main: pthread_create");
exit(1);
}
if (pthread_create(&thread2, NULL, &thread_start, NULL) != 0)
{
perror("main: pthread_create");
exit(1);
}
Reentrant OSS Functions 417