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

📄 c-iosys3.html

📁 this about vxworks operations systems
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<dd><pre class="Code2"><b><a name="83850"><i class="textVariable">result</i> = ioctl (<i class="textVariable">fd</i>, <i class="textVariable">function</i>, <i class="textVariable">arg</i>);</a></b></pre></dl><dd><p class="Body"><a name="83851"> </a>For example, the following call uses the <b class="symbol_UC">FIOBAUDRATE</b> function to set the baud rate of a <i class="acronym_lc">tty</i> device to 9600:</p><dl class="margin"><dd><pre class="Code2"><b><a name="83852"><i class="textVariable">status</i> = ioctl (<i class="textVariable">fd</i>, FIOBAUDRATE, 9600);</a></b></pre></dl><dd><p class="Body"><a name="83856"> </a>The discussion of specific devices in <a href="c-iosys7.html#84371"><i class="title">3.7&nbsp;Devices in VxWorks</i></a> summarizes the <b class="routine"><i class="routine">ioctl</i></b><b>(</b>&nbsp;<b>)</b> functions available for each device. The <b class="routine"><i class="routine">ioctl</i></b><b>(</b>&nbsp;<b>)</b> control codes are defined in <b class="file">ioLib.h</b>. For more information, see the reference entries for specific device drivers.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="83860">3.3.8  &nbsp;&nbsp;Pending on Multiple File Descriptors: The Select Facility</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="83861"> </a>The VxWorks <i class="term">select</i> facility provides a UNIX- and Windows-compatible method for pending on multiple file descriptors. The library <b class="library">selectLib</b> provides both task-level support, allowing tasks to wait for multiple devices to become active, and device driver support, giving drivers the ability to detect tasks that are pended while waiting for I/O on the device. To use this facility, the header file <b class="file">selectLib.h</b> must be included in your application code.</p><dd><p class="Body"><a name="83865"> </a>Task-level support not only gives tasks the ability to simultaneously wait for I/O on multiple devices, but it also allows tasks to specify the maximum time to wait for I/O to become available. For an example of using the<b> </b>select facility to pend on multiple file descriptors, consider a client-server model in which the server is servicing both local and remote clients. The server task uses a pipe to communicate with local clients and a socket to communicate with remote clients. The server task must respond to clients as quickly as possible. If the server blocks waiting for a request on only one of the communication streams, it cannot service requests that come in on the other stream until it gets a request on the first stream. For example, if the server blocks waiting for a request to arrive in the socket, it cannot service requests that arrive in the pipe until a request arrives in the socket to unblock it. This can delay local tasks waiting to get their requests serviced. The select facility solves this problem by giving the server task the ability to monitor both the socket and the pipe and service requests as they come in, regardless of the communication stream used. </p><dd><p class="Body"><a name="83866"> </a>Tasks can block until data becomes available or the device is ready for writing. The <b class="routine"><i class="routine">select</i></b><b>(</b>&nbsp;<b>)</b> routine returns when one or more file descriptors are ready or a timeout has occurred. Using the <b class="routine"><i class="routine">select</i></b><b>(</b>&nbsp;<b>)</b> routine, a task specifies the file descriptors on which to wait for activity. Bit fields are used in the <b class="routine"><i class="routine">select</i></b><b>(</b>&nbsp;<b>)</b> call to specify the read and write file descriptors of interest. When <b class="routine"><i class="routine">select</i></b><b>(</b>&nbsp;<b>)</b> returns, the bit fields are modified to reflect the file descriptors that have become available. The macros for building and manipulating these bit fields are listed in <a href="c-iosys3.html#83876">Table&nbsp;3-3</a>.<p class="table"><h4 class="EntityTitle"><a name="83876"><font face="Helvetica, sans-serif" size="-1" class="sans">Table 3-3:&nbsp;&nbsp;Select Macros</font></a></h4><table border="0" cellpadding="0" cellspacing="0"><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="83880"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Macro</font></b></div></th><th rowspan="1" colspan="1"><div class="CellHeading"><b><a name="83882"> </a><font face="Helvetica, sans-serif" size="-1" class="sans">Function</font></b></div></th></tr><tr><td colspan="20"><hr class="tablerule2"></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83889"> </a><b class="symbol_UC">FD_ZERO</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83891"> </a>Zeros all bits.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83894"> </a><b class="symbol_UC">FD_SET</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83896"> </a>Sets bit corresponding to a specified file descriptor.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83899"> </a><b class="symbol_UC">FD_CLR</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83901"> </a>Clears a specified bit.&nbsp;</div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="83904"> </a><b class="symbol_UC">FD_ISSET</b> &nbsp;</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="83906"> </a>Returns 1 if specified bit is set, otherwise returns 0.&nbsp;</div></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p> </p><dd><p class="Body"><a name="83911"> </a>Applications can use <b class="routine"><i class="routine">select</i></b><b>(</b>&nbsp;<b>)</b> with any character I/O devices that provide support for this facility (for example, pipes, serial devices, and sockets). For information on writing a device driver that supports <b class="routine"><i class="routine">select</i></b><b>(</b>&nbsp;<b>)</b>, see <a href="c-iosys9.html#85695"><i class="title">Implementing select(&nbsp;)</i></a>.</p></dl></dl><h4 class="EntityTitle"><a name="83917"><font face="Helvetica, sans-serif" size="-1" class="sans">Example 3-1:&nbsp;&nbsp;The Select Facility</font></a></h4><dl class="margin"><dl class="margin"><dd><pre class="Code"><b><a name="83918">/* selServer.c - select example   * In this example, a server task uses two pipes: one for normal-priority   * requests, the other for high-priority requests. The server opens both   * pipes and blocks while waiting for data to be available in at least one   * of the pipes.   */</a></b><dd> <b><a name="83921">#include "vxWorks.h" #include "selectLib.h" #include "fcntl.h"</a></b><dd> <b><a name="83925">#define MAX_FDS 2 #define MAX_DATA 1024 #define PIPEHI  "/pipe/highPriority" #define PIPENORM "/pipe/normalPriority"</a></b><dd> <b><a name="83930">/************************************************************************ * selServer - reads data as it becomes available from two different pipes  * * Opens two pipe fds, reading from whichever becomes available. The  * server code assumes the pipes have been created from either another  * task or the shell. To test this code from the shell do the following: *  -&gt; ld &lt; selServer.o *  -&gt; pipeDevCreate ("/pipe/highPriority", 5, 1024) *  -&gt; pipeDevCreate ("/pipe/normalPriority", 5, 1024) *  -&gt; fdHi = open ("/pipe/highPriority", 1, 0) *  -&gt; fdNorm = open ("/pipe/normalPriority", 1, 0) *  -&gt; iosFdShow *  -&gt; sp selServer *  -&gt; i * At this point you should see selServer's state as pended. You can now * write to either pipe to make the selServer display your message. *  -&gt; write fdNorm, "Howdy", 6 *  -&gt; write fdHi, "Urgent", 7 */</a></b><dd> <b><a name="83949">STATUS selServer (void)   {   struct fd_set readFds;      /* bit mask of fds to read from */   int      fds[MAX_FDS];   &nbsp;&nbsp;&nbsp;/* array of fds on which to pend */   int      width;       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* number of fds on which to pend */   int      i;         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* index for fd array */   char     buffer[MAX_DATA]; /* buffer for data that is read */</a></b><dd> <b><a name="83957">/* open file descriptors */   if ((fds[0] = open (PIPEHI, O_RDONLY, 0)) == ERROR)     return (ERROR);   if ((fds[1] = open (PIPENORM, O_RDONLY, 0)) == ERROR)     return (ERROR);</a></b><dd> <b><a name="83963">/* loop forever reading data and servicing clients */   FOREVER     {     /* clear bits in read bit mask */     FD_ZERO (&amp;readFds);</a></b><dd> <b><a name="83969">/* initialize bit mask */     FD_SET (fds[0], &amp;readFds);     FD_SET (fds[1], &amp;readFds);     width = (fds[0] &gt; fds[1]) ? fds[0] : fds[1];     width++;</a></b><dd> <b><a name="83975">/* pend, waiting for one or more fds to become ready */     if (select (width, &amp;readFds, NULL, NULL, NULL) == ERROR)       return (ERROR);</a></b><dd> <b><a name="83979">/* step through array and read from fds that are ready */     for (i=0; i&lt; MAX_FDS; i++)       {       /* check if this fd has data to read */       if (FD_ISSET (fds[i], &amp;readFds))         {         /* typically read from fd now that it is ready */         read (fds[i], buffer, MAX_DATA);         /* normally service request, for this example print it */         printf ("SELSERVER Reading from %s: %s\n",              (i == 0) ? PIPEHI : PIPENORM, buffer);         }       }     }   }</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-iosys2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-iosys4.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 + -