⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-iosys6.html

📁 this about vxworks operations systems
💻 HTML
📖 第 1 页 / 共 3 页
字号:
 <b><a name="84283">#define BUFFER_SIZE 200</a></b><dd> <b><a name="84285">/************************************************************************ * aioExample - use AIO library * * This example shows the basic functions of the AIO library. * * RETURNS: OK if successful, otherwise ERROR. */</a></b><dd> <b><a name="84287">STATUS aioExample (void)   {   int       fd;   static char   exFile [] = "/pipe/1stPipe";   struct aiocb  aiocb_read; /* read aiocb */   struct aiocb  aiocb_write; /* write aiocb */   static char *  test_string = "testing 1 2 3";   char      buffer [BUFFER_SIZE]; /* buffer for read aiocb */</a></b><dd> <b><a name="84289">pipeDevCreate (exFile, 50, 100);</a></b><dd> <b><a name="84291">if ((fd = open (exFile, O_CREAT | O_TRUNC | O_RDWR, 0666)) ==     ERROR)   {   printf ("aioExample: cannot open %s errno 0x%x\n", exFile, errno);   return (ERROR);   }</a></b><dd> <b><a name="84293">printf ("aioExample: Example file = %s\tFile descriptor = %d\n",       exFile, fd); </a></b><dd> <b><a name="84295">/* initialize read and write aiocbs */   bzero ((char *) &amp;aiocb_read, sizeof (struct aiocb));   bzero ((char *) buffer, sizeof (buffer));   aiocb_read.aio_fildes = fd;   aiocb_read.aio_buf = buffer;   aiocb_read.aio_nbytes = BUFFER_SIZE;   aiocb_read.aio_reqprio = 0;</a></b><dd> <b><a name="84297">bzero ((char *) &amp;aiocb_write, sizeof (struct aiocb));   aiocb_write.aio_fildes = fd;   aiocb_write.aio_buf = test_string;   aiocb_write.aio_nbytes = strlen (test_string);   aiocb_write.aio_reqprio = 0;</a></b><dd> <b><a name="84299">/* initiate the read */   if (aio_read (&amp;aiocb_read) == -1)     printf ("aioExample: aio_read failed\n");</a></b><dd> <b><a name="84301">/* verify that it is in progress */   if (aio_error (&amp;aiocb_read) == EINPROGRESS)     printf ("aioExample: read is still in progress\n");</a></b><dd> <b><a name="84303">/* write to pipe - the read should be able to complete */   printf ("aioExample: getting ready to initiate the write\n");   if (aio_write (&amp;aiocb_write) == -1)     printf ("aioExample: aio_write failed\n"); </a></b><dd> <b><a name="84305">/* wait til both read and write are complete */   while ((aio_error (&amp;aiocb_read) == EINPROGRESS) ||        (aio_error (&amp;aiocb_write) == EINPROGRESS))     taskDelay (1);</a></b><dd> <b><a name="84307">/* print out what was read */   printf ("aioExample: message = %s\n", buffer);</a></b><dd> <b><a name="84309">/* clean up */   if (aio_return (&amp;aiocb_read) == -1)     printf ("aioExample: aio_return for aiocb_read failed\n");   if (aio_return (&amp;aiocb_write) == -1)     printf ("aioExample: aio_return for aiocb_write failed\n");</a></b><dd> <b><a name="84311">close (fd);   return (OK);   }</a></b></pre></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84312">Alternatives for Testing AIO Completion</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84314"> </a>A task can determine whether an AIO request is complete in any of the following ways: </p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84315"> </a>Check the result of <b class="routine"><i class="routine">aio_error</i></b><b>(&nbsp;)</b> periodically, as in the previous example, until the status of an AIO request is no longer <b class="symbol_UC">EINPROGRESS</b>.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84317"> </a>Use <b class="routine"><i class="routine">aio_suspend</i></b><b>(&nbsp;)</b> to suspend the task until the AIO request is complete.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84318"> </a>Use signals to be informed when the AIO request is complete. </li></ul></p></dl><dl class="margin"><dd><p class="Body"><a name="84319"> </a>The following example is similar to the preceding <b class="routine"><i class="routine">aioExample</i></b><b>(&nbsp;)</b>, except that it uses signals to be notified when the write is complete. If you test this from the shell, spawn the routine to run at a lower priority than the AIO system tasks to assure that the test routine does not block completion of the AIO request. (For details on the shell, see the <i class="title">Tornado User's Guide: Shell</i>.)</p></dl></dl><h4 class="EntityTitle"><a name="84320"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 3-3:&nbsp;&nbsp;Asynchronous I/O with Signals</font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="84321">/* aioExSig.c - example code for using signals with asynchronous I/O */</a></b><dd> <b><a name="84323">/* includes */</a></b><dd> <b><a name="84324">#include "vxWorks.h" #include "aio.h" #include "errno.h"</a></b><dd> <b><a name="84326">/* defines */</a></b><dd> <b><a name="84327">#define BUFFER_SIZE   200 #define LIST_SIZE    1 #define EXAMPLE_SIG_NO  25 /* signal number */</a></b><dd> <b><a name="84329">/* forward declarations */</a></b><dd> <b><a name="84330">void mySigHandler (int sig, struct siginfo * info, void * pContext);</a></b><dd> <b><a name="84332">/************************************************************************ * aioExampleSig - use AIO library. * * This example shows the basic functions of the AIO library. * Note if this is run from the shell it must be spawned. Use: *  -&gt; sp aioExampleSig * * RETURNS: OK if successful, otherwise ERROR. */</a></b><dd> <b><a name="84334">STATUS aioExampleSig (void)   {   int           fd;   static char       exFile [] = "/pipe/1stPipe";   struct aiocb      aiocb_read;      /* read aiocb */   static struct aiocb   aiocb_write;      /* write aiocb */   struct sigaction    action;        /* signal info */   static char *      test_string = "testing 1 2 3";   char          buffer [BUFFER_SIZE]; /* aiocb read buffer */</a></b><dd> <b><a name="84336">pipeDevCreate (exFile, 50, 100);</a></b><dd> <b><a name="84338">if ((fd = open (exFile, O_CREAT | O_TRUNC| O_RDWR, 0666)) == ERROR)     {     printf ("aioExample: cannot open %s errno 0x%x\n", exFile, errno);     return (ERROR);     }</a></b><dd> <b><a name="93621">printf ("aioExampleSig: Example file = %s\tFile descriptor = %d\n",        exFile, fd); </a></b><dd> <b><a name="84344">/* set up signal handler for EXAMPLE_SIG_NO */    action.sa_sigaction = mySigHandler;   action.sa_flags = SA_SIGINFO;   sigemptyset (&amp;action.sa_mask);   sigaction (EXAMPLE_SIG_NO, &amp;action, NULL);</a></b><dd> <b><a name="84346">/* initialize read and write aiocbs */    bzero ((char *) &amp;aiocb_read, sizeof (struct aiocb));   bzero ((char *) buffer, sizeof (buffer));   aiocb_read.aio_fildes = fd;   aiocb_read.aio_buf = buffer;   aiocb_read.aio_nbytes = BUFFER_SIZE;   aiocb_read.aio_reqprio = 0;</a></b><dd> <b><a name="84348">bzero ((char *) &amp;aiocb_write, sizeof (struct aiocb));   aiocb_write.aio_fildes = fd;   aiocb_write.aio_buf = test_string;   aiocb_write.aio_nbytes = strlen (test_string);   aiocb_write.aio_reqprio = 0;</a></b><dd> <b><a name="84350">/* set up signal info */    aiocb_write.aio_sigevent.sigev_signo = EXAMPLE_SIG_NO;   aiocb_write.aio_sigevent.sigev_notify = SIGEV_SIGNAL;   aiocb_write.aio_sigevent.sigev_value.sival_ptr =                          (void *) &amp;aiocb_write;</a></b><dd> <b><a name="84352">/* initiate the read */    if (aio_read (&amp;aiocb_read) == -1)     printf ("aioExampleSig: aio_read failed\n");</a></b><dd> <b><a name="84354">/* verify that it is in progress */    if (aio_error (&amp;aiocb_read) == EINPROGRESS)     printf ("aioExampleSig: read is still in progress\n");</a></b><dd> <b><a name="84356">/* write to pipe - the read should be able to complete */    printf ("aioExampleSig: getting ready to initiate the write\n");   if (aio_write (&amp;aiocb_write) == -1)     printf ("aioExampleSig: aio_write failed\n");</a></b><dd> <b><a name="84358">/* clean up */    if (aio_return (&amp;aiocb_read) == -1)     printf ("aioExampleSig: aio_return for aiocb_read failed\n");   else     printf ("aioExampleSig: aio read message = %s\n",          aiocb_read.aio_buf);</a></b><dd> <b><a name="84360">close (fd);   return (OK);   }</a></b><dd> <b><a name="84362">void mySigHandler    (   int        sig,   struct siginfo * info,   void *      pContext   )</a></b><dd> <b><a name="84363">  {   /* print out what was read */    printf ("mySigHandler: Got signal for aio write\n");</a></b><dd> <b><a name="95759">  /* write is complete so let's do cleanup for it here */    if (aio_return (info-&gt;si_value.sival_ptr) == -1)     {     printf ("mySigHandler: aio_return for aiocb_write failed\n");     printErrno (0);     }   }</a></b></pre></dl></dl><a name="foot"><hr></a><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-iosys.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-iosys5.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-iosys7.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc.    conversion tool:  Quadralay WebWorks Publisher 4.0.11    template:         CSS Template, Jan 1998 - Jefro --->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -