Open System Services Programmer's Guide
/*****************************************************************/
/* prepare I/O buffer (page aligned, paged into physical memory) */
/*****************************************************************/
if ((iobuf = malloc(IOSIZE)) == NULL)
{
printf("*** ERROR in OSS_write_thread: unable to allocate I/O buffer
***\n");
exit(0);
}
memset(iobuf, 0, IOSIZE);
/*********************/
/* open the OSS file */
/*********************/
if ((fd = open(OSS_write_file, O_WRONLY | O_NONBLOCK | O_CREAT | O_TRUNC,
S_IRWXU)) < 0)
{
printf("*** ERROR in OSS_write_thread: open() of %s failed w/error
%d ***\n", OSS_write_file, errno);
exit(0);
}
/***********************************************/
/* write the OSS file in a thread-aware manner */
/***********************************************/
while (currsize < WRITE_FILESIZE)
{
nbytes = write(fd, iobuf, IOSIZE);
if (nbytes < 0)
{
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
{
/**************************************************************************/
/* NOTE that this code does not execute for regular (disk) files, because */
/* write() on a regular file never returns EWOULDBLOCK or EAGAIN */
/**************************************************************************/
ret = spt_fd_write_ready(fd, NULL);
if (ret != 0)
{
printf("*** ERROR in OSS_write_thread: spt_fd_write_ready()
failed w/error %d ***\n", ret);
exit(0);
}
}
else
{
printf("*** ERROR in OSS_write_thread: write() failed w/error %d
***\n", errno);
exit(0);
}
}
else /* write successful */
{
currsize += nbytes;
}
} /* while */
close(fd);
Thread-Aware and Nonblocking OSS Functions 363