Open System Services Programmer's Guide
/*
*-----------------------------------------------------------------------
*
* OSS_write_thread --
*
* Description:
*
* This thread writes an OSS file using OSS I/O.
* Note that OSS I/O on regular files is serialized and only one OSS I/O
* per open can occur at a given time. Even though we use the thread
* aware library,the entire program blocks while the OSS write()
* function performs the I/O.
*
* 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)
{
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))
{
Thread-Aware and Nonblocking OSS Functions 353