Open System Services Programmer's Guide
Example 82 $RECEIVE Server
#include <cextdecs.h(FILE_OPEN_)>
#include <spthread.h>
short filenum;
void *
thread_start(void *parms)
{
long bytesread, error;
char buffer[2];
short receive_info[17];
while (1)
{
error = spt_RECEIVEREAD(filenum, buffer,
(short)sizeof(buffer), &bytesread, -1,
receive_info, NULL);
if (error != 0) break;
// Do real work here!
error = spt_REPLYX("server's reply.", 15, NULL,
receive_info[2], 0);
if (error != 0) break;
}
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)
{
fprintf(stderr,"main: FILE_OPEN_ failed.\n");
exit(1);
}
if (spt_INITRECEIVE(filenum, 2) != 0)
{
fprintf(stderr,"main: spt_INITRECEIVE failed\n");
exit(1);
}
if (pthread_create(&thread1, NULL, &thread_start, NULL) != 0)
{
perror("main: pthread_create");
exit(1);
}
} exit(0)
if (pthread_create(&thread2, NULL, &thread_start, NULL) != 0)
{
perror("main: pthread_create");
exit(1);
}
if (pthread_join(thread1, NULL) != 0)
{
perror("main: pthread_join");
exit(1);
}
Reentrant OSS Functions 375