Open System Services Programmer's Guide

/*******************************************************************/
/* NOTE that this code does not execute for regular (disk) files, */
/* because read() on a regular file never returns EWOULDBLOCK or */
/* EAGAIN */
/*******************************************************************/
ret = spt_fd_read_ready(fd, NULL);
if (ret != 0)
{
printf("*** ERROR in OSS_read_thread: spt_fd_read_ready()
failed w/err %d\n",ret);
exit(0);
}
}
else
{
printf("*** ERROR in OSS_read_thread: read() failed w/error
%d ***\n",errno);
exit(0);
}
}
else if (nbytes == 0) /* EOF */
{
break;
}
else /* read successful */
{
filesize += nbytes;
}
} /* while */
close(fd);
printf("==> OSS_read_thread() read %ld bytes from file %s\n", filesize,
OSS_read_file);
return(NULL);
}
/*
*--------------------------------------------------------------------
*
* OSS_write_thread --
*
* Description:
*
* This thread writes an OSS file using OSS I/O. Because this program
* uses the define SPT_THREAD_AWARE_XNONBLOCK, the write() function is
* mapped to the spt_writez() function, which is thread-aware and blocks
* the thread instead of the entire process. Other threads are free to do
* work while this thread is blocked waiting for an I/O completion.
*
* Results:
* none.
*
*---------------------------------------------------------------------
*/
void *OSS_write_thread(void *OSS_write_file)
{
int fd;
int nbytes;
char *iobuf;
int ret;
long long currsize = 0;
362 Using the Standard POSIX Threads Library