Open System Services Programmer's Guide
 /**********************************************/
 /* read the OSS file in a thread aware manner */
 /**********************************************/
 while (1)
 {
 nbytes = read(fd, iobuf, IOSIZE);
 if (nbytes < 0)
 {
 if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
 {
/**************************************************************************/
/* 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;
/*********************************************************************/
/* When doing Non-Blocking OSS I/O to diskfiles, it is a good */
/* idea to call sched_yield(), otherwise this thread won't give */
/* up control until the file is completely written. This is because */
/* write() never returns EWOULDBLOCK for a diskfile. */
/*********************************************************************/
 sched_yield(); 
 }
 } /* while */
 close(fd);
 printf("==> OSS_read_thread() read %ld bytes from file %s\n", filesize,
 OSS_read_file);
 return(NULL);
}
352 Using the Standard POSIX Threads Library










