📄 aiopxlib.html
字号:
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/aioPxLib.html - generated by refgen from aioPxLib.c --> <title> aioPxLib </title></head><body bgcolor="#FFFFFF"> <hr><a name="top"></a><p align=right><a href="libIndex.htm"><i>VxWorks API Reference : OS Libraries</i></a></p></blockquote><h1>aioPxLib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>aioPxLib</strong> - asynchronous I/O (AIO) library (POSIX) </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><a href="./aioPxLib.html#aioPxLibInit">aioPxLibInit</a>( )</b> - initialize the asynchronous I/O (AIO) library<br><b><a href="./aioPxLib.html#aio_read">aio_read</a>( )</b> - initiate an asynchronous read (POSIX)<br><b><a href="./aioPxLib.html#aio_write">aio_write</a>( )</b> - initiate an asynchronous write (POSIX)<br><b><a href="./aioPxLib.html#lio_listio">lio_listio</a>( )</b> - initiate a list of asynchronous I/O requests (POSIX)<br><b><a href="./aioPxLib.html#aio_suspend">aio_suspend</a>( )</b> - wait for asynchronous I/O request(s) (POSIX)<br><b><a href="./aioPxLib.html#aio_error">aio_error</a>( )</b> - retrieve error status of asynchronous I/O operation (POSIX)<br><b><a href="./aioPxLib.html#aio_return">aio_return</a>( )</b> - retrieve return status of asynchronous I/O operation (POSIX)<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p>This library implements asynchronous I/O (AIO) according to the definition given by the POSIX standard 1003.1b (formerly 1003.4, Draft 14). AIO provides the ability to overlap application processing and I/O operations initiated by the application. With AIO, a task can perform I/O simultaneously to a single file multiple times or to multiple files.<p>After an AIO operation has been initiated, the AIO proceeds in logical parallel with the processing done by the application.The effect of issuing an asynchronous I/O request is as if a separatethread of execution were performing the requested I/O.<p></blockquote><h4>AIO LIBRARY</h4><blockquote><p>The AIO library is initialized by calling <b><a href="./aioPxLib.html#aioPxLibInit">aioPxLibInit</a>( )</b>, whichshould be called once (typically at system start-up) after the I/O system has already been initialized.<p></blockquote><h4>AIO COMMANDS </h4><blockquote><p>The file to be accessed asynchronously is opened via the standard open call. Open returns a file descriptor which is used in subsequent AIO calls.<p>The caller initiates asynchronous I/O via one of the following routines: <dl><dt><b><a href="./aioPxLib.html#aio_read">aio_read</a>( )</b><dd>initiates an asynchronous read<dt><b><a href="./aioPxLib.html#aio_write">aio_write</a>( )</b><dd>initiates an asynchronous write<dt><b><a href="./aioPxLib.html#lio_listio">lio_listio</a>( )</b><dd>initiates a list of asynchronous I/O requests</dl>Each of these routines has a return value and error value associated with it; however, these values indicate only whether the AIO request was successfully submitted (queued), not the ultimate success orfailure of the AIO operation itself. <p>There are separate return and error values associated with the success orfailure of the AIO operation itself. The error status can be retrievedusing <b><a href="./aioPxLib.html#aio_error">aio_error</a>( )</b>; however, until the AIO operation completes, the errorstatus will be EINPROGRESS. After the AIO operation completes, the returnstatus can be retrieved with <b><a href="./aioPxLib.html#aio_return">aio_return</a>( )</b>.<p>The <b>aio_cancel( )</b> call cancels a previously submitted AIO request. The<b><a href="./aioPxLib.html#aio_suspend">aio_suspend</a>( )</b> call waits for an AIO operation to complete.<p>Finally, the <b><a href="./aioPxShow.html#aioShow">aioShow</a>( )</b> call (not a standard POSIX function) displaysoutstanding AIO requests.<p></blockquote><h4>AIO CONTROL BLOCK</h4><blockquote><p>Each of the calls described above takes an AIO control block (<b>aiocb</b>) asan argument. The calling routine must allocate space for the <b>aiocb</b>, andthis space must remain available for the duration of the AIO operation.(Thus the <b>aiocb</b> must not be created on the task's stack unless thecalling routine will not return until after the AIO operation is completeand <b><a href="./aioPxLib.html#aio_return">aio_return</a>( )</b> has been called.) Each <b>aiocb</b> describes a single AIOoperation. Therefore, simultaneous asynchronous I/O operations using thesame <b>aiocb</b> are not valid and produce undefined results.<p>The <b>aiocb</b> structure and the data buffers referenced by it are used by the system to perform the AIO request. Therefore, once the <b>aiocb</b> hasbeen submitted to the system, the application must not modify the <b>aiocb</b> structure until after a subsequent call to <b><a href="./aioPxLib.html#aio_return">aio_return</a>( )</b>. The <b><a href="./aioPxLib.html#aio_return">aio_return</a>( )</b> call retrieves the previously submitted AIO data structures from the system.After the <b><a href="./aioPxLib.html#aio_return">aio_return</a>( )</b> call, the calling application can modify the<b>aiocb</b>, free the memory it occupies, or reuse it for another AIO call. <p>As a result, if space for the <b>aiocb</b> is allocated off the stack the task should not be deleted (or complete running) until the <b>aiocb</b> has been retrieved from the system via an <b><a href="./aioPxLib.html#aio_return">aio_return</a>( )</b>.<p>The <b>aiocb</b> is defined in <b>aio.h</b>. It has the following elements:<pre> struct { int aio_fildes; off_t aio_offset; volatile void * aio_buf; size_t aio_nbytes; int aio_reqprio; struct sigevent aio_sigevent; int aio_lio_opcode; AIO_SYS aio_sys; } aiocb</pre><dl><dt><b>aio_fildes</b><dd>file descriptor for I/O.<dt><b>aio_offset</b><dd>offset from the beginning of the file where theAIO takes place. Note that performing AIO on the file does not cause the offset location to automatically increase as in read and write;the caller must therefore keep track of the location of reads and writes made to the file (see POSIX COMPLIANCE below). <dt><b>aio_buf</b><dd>address of the buffer from/to which AIO is requested.<dt><b>aio_nbytes</b><dd>number of bytes to read or write.<dt><b>aio_reqprio</b><dd>amount by which to lower the priority of an AIO request. EachAIO request is assigned a priority; this priority, based on the callingtask's priority, indicates the desired order of execution relative toother AIO requests for the file. The <b>aio_reqprio</b> member allows thecaller to lower (but not raise) the AIO operation priority by thespecified value. Valid values for <b>aio_reqprio</b> are in the range of zerothrough <b>AIO_PRIO_DELTA_MAX</b>. If the value specified by <b>aio_req_prio</b>results in a priority lower than the lowest possible task priority, thelowest valid task priority is used.<dt><b>aio_sigevent</b><dd>(optional) if nonzero, the signal to return on completion of an operation.<dt><b>aio_lio_opcode</b><dd>operation to be performed by a <b><a href="./aioPxLib.html#lio_listio">lio_listio</a>( )</b> call; valid entries include<b>LIO_READ</b>, <b>LIO_WRITE</b>, and <b>LIO_NOP</b>. <dt><b>aio_sys</b><dd>a Wind River Systems addition to the <b>aiocb</b> structure; it isused internally by the system and must not be modified by the user.</dl><p></blockquote><h4>EXAMPLES</h4><blockquote><p>A writer could be implemented as follows:<pre> if ((pAioWrite = calloc (1, sizeof (struct aiocb))) == NULL) { printf ("calloc failed\n"); return (ERROR); } pAioWrite->aio_fildes = fd; pAioWrite->aio_buf = buffer; pAioWrite->aio_offset = 0; strcpy (pAioWrite->aio_buf, "test string"); pAioWrite->aio_nbytes = strlen ("test string"); pAioWrite->aio_sigevent.sigev_notify = SIGEV_NONE; aio_write (pAioWrite); /* . . do other work . . */ /* now wait until I/O finishes */ while (aio_error (pAioWrite) == EINPROGRESS) taskDelay (1); aio_return (pAioWrite); free (pAioWrite);</pre> A reader could be implemented as follows:<p><pre> /* initialize signal handler */ action1.sa_sigaction = sigHandler; action1.sa_flags = SA_SIGINFO; sigemptyset(&action1.sa_mask); sigaction (TEST_RT_SIG1, &action1, NULL); if ((pAioRead = calloc (1, sizeof (struct aiocb))) == NULL) { printf ("calloc failed\n"); return (ERROR); } pAioRead->aio_fildes = fd; pAioRead->aio_buf = buffer; pAioRead->aio_nbytes = BUF_SIZE; pAioRead->aio_sigevent.sigev_signo = TEST_RT_SIG1; pAioRead->aio_sigevent.sigev_notify = SIGEV_SIGNAL; pAioRead->aio_sigevent.sigev_value.sival_ptr = (void *)pAioRead; aio_read (pAioRead); /* . . do other work . . */</pre>The signal handler might look like the following:<p><pre>void sigHandler ( int sig, struct siginfo info, void * pContext ) { struct aiocb * pAioDone; pAioDone = (struct aiocb *) info.si_value.sival_ptr; aio_return (pAioDone); free (pAioDone); }</pre></blockquote><h4>POSIX COMPLIANCE</h4><blockquote><p>Currently VxWorks does not support the <b>O_APPEND</b> flag in the open call. Therefore, the user must keep track of the offset in the file that the asynchronous writes occur (as in the case of reads). The <b>aio_offset</b>field is used to specify that file position.<p>In addition, VxWorks does not currently support synchronized I/O.<p></blockquote><h4>INCLUDE FILES</h4><blockquote><p><b>aio.h</b><p></blockquote><h4>SEE ALSO</h4><blockquote><p>POSIX 1003.1b document<p><hr><a name="aioPxLibInit"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>aioPxLibInit( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>aioPxLibInit( )</strong> - initialize the asynchronous I/O (AIO) library</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS aioPxLibInit ( int lioMax /* max outstanding lio calls */ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -