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 = put_fd_read_ready(fd, NULL);
if (ret != 0)
{
my_printf("*** ERROR in OSS_read_thread:
put_fd_read_ready() \ failed w/err %d\n",ret);
exit(0);
}
}
else
{
my_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);
my_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 _PUT_MODEL_, the write() function is
* mapped to the thread—aware version of the write() function, which
* 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;
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
if ((iobuf = malloc(IOSIZE)) == NULL)
{
Thread-Aware and Nonblocking OSS Functions 403