📄 streams.doc8.html
字号:
</td><td colspan=1 rowspan=1><div class="CellBody"><a name="85704" class="autotag"> </a>The <b class="routine"><i class="routine">write</i></b><b>( )</b> routine on an unconnected socket fails with error <b>ENOTCONN</b>.</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="85706" class="autotag"> </a>The <b class="routine"><i class="routine">write</i></b><b>( )</b> routine on an unconnected socket fails with error <b>ERANGE</b><b class="keyword">.</b></div></td></tr><tr valign="top"><td colspan=1 rowspan=1><div class="CellBody"><a name="85708" class="autotag"> </a>Disconnected sockets and <b class="routine"><i class="routine">write</i></b><b>( )</b> or <b class="routine"><i class="routine">send</i></b><b>( )</b></div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="85710" class="autotag"> </a>If a <b class="routine"><i class="routine">write</i></b><b>( )</b> or <b class="routine"><i class="routine">send</i></b><b>( )</b> is attempted on a disconnected socket, the system call returns <b>EPIPE</b>, but no signal is generated.</div></td><td colspan=1 rowspan=1><div class="CellBody"><a name="85712" class="autotag"> </a>When a <b>T_DISCON_IND</b> primitive is received, <b>sockmod</b> sets the stream head write-side error state to <b>EPIPE</b>. Subsequent <b class="routine"><i class="routine">write</i></b><b>( )</b> or <b class="routine"><i class="routine">send</i></b><b>( )</b> calls will return an error, but no signal is generated.</div></td></tr><tr valign="top"><td colspan=1 rowspan=1></td><td colspan=1 rowspan=1></td><td colspan=1 rowspan=1></td></tr><tr><td colspan="20"><hr class="tablerule"></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p></p></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="77304" class="autotag">3.2.4 Addition of Transport Providers to WindNet STREAMS Sockets</a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="77305" class="autotag"> </a>The STREAMS socket library has an inherent deficiency that has been remedied by WindNet STREAMS: In STREAMS, there is no transport provider independence at the socket layer because the socket associates itself with the transport provider by opening the transport provider device; thus, <b class="routine"><i class="routine">socket</i></b><b>( )</b> cannot open different providers based on socket parameter values. The WindNet STREAMS socket implementation provides transport independence through a routine, <b class="routine"><i class="routine">strmSockProtoAdd</i></b><b>( )</b>. </p><p class="Body"><a name="90498" class="autotag"> </a>The <b class="routine"><i class="routine">strmSockProtoAdd</i></b><b>( )</b> routine registers a new transport provider by adding an entry to an internally-maintained table that contains information about available transport providers. The table's data is based on the following three parameters passed by <b class="routine"><i class="routine">strmSockProtoAdd</i></b><b>( )</b>:</p><dl class="margin"><dd><div class="Item2"><a name="90499" class="autotag"> </a><font face="Palatino, serif"><i class="textVariable">family</i></font></div><dl class="margin"><dd><div class="Indent2"><a name="95307" class="autotag"> </a>specifies the address family </div><br></dd></dl><div class="Item2"><a name="90500" class="autotag"> </a><font face="Palatino, serif"><i class="textVariable">type</i></font></div><dl class="margin"><dd><div class="Indent2"><a name="95313" class="autotag"> </a>defines the socket type</div><br></dd></dl><div class="Item2"><a name="90501" class="autotag"> </a><font face="Palatino, serif"><i class="textVariable">devName</i></font></div><dl class="margin"><dd><div class="Indent2"><a name="95315" class="autotag"> </a>defines the transport provider device name</div><br></dd></dl></dd></dl><p class="Body"><a name="90490" class="autotag"> </a>When a socket call is made, the socket library, where the table is located, decides which transport provider to use based on the parameters passed by the socket call. The <b class="routine"><i class="routine">strmSockProtoAdd</i></b><b>( )</b> routine is usually invoked at system initialization. It must be called before <b class="routine"><i class="routine">socket</i></b><b>( )</b>.</p><p class="Body"><a name="79410" class="autotag"> </a>The <b class="routine"><i class="routine">strmSockProtoAdd</i></b><b>( )</b> routine creates an association among the parameter values--for a unique <font face="Palatino, serif"><i class="textVariable">family</i></font> and <font face="Palatino, serif"><i class="textVariable">type</i></font>, there is a unique transport provider specified by <font face="Palatino, serif"><i class="textVariable">devName</i></font>-- so when <b class="routine"><i class="routine">socket</i></b><b>( )</b> is called, the parameters that have been passed to it prompt the library to select the appropriate transport provider. For example, the following code fragment associates socket calls using the address family <b>AF_INET</b> and the socket type <b>SOCK_STREAM</b> with the transport provider <b class="file">/dev/tcp</b>. The socket call establishes the transport endpoint using the TCP transport provider.</p></dd></dl><dl class="margin"><dd><pre class="Code"><a name="76397" class="autotag">strmSockProtoAdd (AF_INET, SOCK_STREAM,"/dev/tcp");</a><a name="76398" class="autotag">socket (AF_INET,SOCK_STREAM,0);</a></pre></dd></dl><dl class="margin"><dd><p class="Body"><a name="79448" class="autotag"> </a>In the following code fragment, socket calls that use the address family <b>AF_INET</b> and socket type <b>SOCK_DGRAM</b> are associated with the transport provider <b class="file">/dev/udp</b>. The socket call establishes the transport endpoint using the UDP transport provider. </p></dd></dl><dl class="margin"><dd><pre class="Code"><a name="76400" class="autotag">strmSockProtoAdd (AF_INET, SOCK_DGRAM,"/dev/udp");</a><a name="76401" class="autotag">socket (AF_INET,SOCK_DGRAM,0);</a></pre></dd></dl><dl class="margin"><dd><p class="Body"><a name="79475" class="autotag"> </a>In this third example, socket calls that use the address family <b>AF_CCITT</b> have been associated with the socket type <b>SOCK_STREAM</b> with the transport provider <b class="file">/dev/x25</b>. </p></dd></dl><dl class="margin"><dd><pre class="Code"><a name="76403" class="autotag">strmSockProtoAdd (AF_CCITT,SOCK_STREAM,"/dev/x25");</a><a name="83953" class="autotag">socket (AF_CCITT,SOCK_STREAM,0);</a></pre></dd></dl></dd></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="94945" class="autotag">3.2.5 Using Native VxWorks Sockets and WindNet STREAMS Sockets</a></i></h4></font><dl class="margin"><dd><dl class="margin"><dd><p class="Body"><a name="94946" class="autotag"> </a>WindNet STREAMS sockets are designed to co-exist with VxWorks BSD sockets, which are discussed in the <i class="title">VxWorks Programmer's Guide: Network</i>. This is achieved using a layered operating environment, that is, the VxWorks socket library is a layer above the BSD socket and WindNet STREAMS socket layers, as shown in <a href="streams.doc8.html#94975"><i class="title">Figure 10</i></a>. <div class="frame"><h4 class="EntityTitle"><a name="94975" class="autotag"><font face="Helvetica, sans-serif" size="-1" class="sans">Figure 10. Socket Architecture in WindNet STREAMS</font></a></h4><div class="CellBody"><a name="94972" class="autotag"> </a><img class="figure" border="0" alt="" src="images/streams.doc.anc9.gif"></div></div></p><p class="Body"><a name="90551" class="autotag"> </a>Calls to routines in the VxWorks socket library are directed to the appropriate underlying socket library, either BSD or WindNet STREAMS, based on the default defined in <b class="file">configAll.h</b> or the parameters passed to the socket layer. The BSD socket library is configured into the VxWorks system image, making it the system default. You can define configuration constants to make WindNet STREAMS sockets an alternate default. The routine <b class="routine"><i class="routine">socket</i></b><b>( )</b>creates a communication endpoint in either the BSD or WindNet STREAMS socket library based on the parameters passed to it, and thus designates the socket library to be used by your application.</p><p class="Body"><a name="76418" class="autotag"> </a>The following constants have been newly added to <b class="file">configAll.h</b> and configure the specified socket library into VxWorks and make it the default choice:</p></dd></dl><dl class="margin"><dd><div class="Item"><a name="76423" class="autotag"> </a><b>INCLUDE_BSD_SOCKETS</b></div><dl class="margin"><dd><div class="Indent"><a name="95317" class="autotag"> </a>This constant is defined by default. It ensures that socket calls with the first parameter defined as <b>AF_INET</b> or <b>AF_INET_BSD</b> access the BSD socket library. </div><br></dd></dl><div class="Item"><a name="76424" class="autotag"> </a><b>INCLUDE_STREAMS_SOCKET</b></div><dl class="margin"><dd><div class="Indent"><a name="95319" class="autotag"> </a>Define this constant to include the STREAMS socket library into VxWorks.</div><br></dd></dl><div class="Item"><a name="89668" class="autotag"> </a><b>DEFAULT_STREAMS_SOCKET</b></div><dl class="margin"><dd><div class="Indent"><a name="95321" class="autotag"> </a>Define this constant to ensure that socket calls using <b>AF_INET</b> as the first parameter access the WindNet STREAMS socket library. </div><br><div class="Indent"><a name="89737" class="autotag"> </a>The following two VxWorks-specific constants are newly defined in <b class="file">sys/socket.h</b> and when passed to <b class="routine"><i class="routine">socket</i></b><b>( )</b> they direct socket application calls to the related socket library: </div><br></dd></dl><div class="Item"><a name="89738" class="autotag"> </a><b>AF_INET_BSD</b></div><dl class="margin"><dd><div class="Indent"><a name="95323" class="autotag"> </a>This address family provides access to the BSD socket library when it is used as the first parameter in the <b class="routine"><i class="routine">socket</i></b><b>( )</b> call. It is used when <b>DEFAULT_STREAM_SOCKET</b> is defined in <b class="file">configAll.h</b>.</div><br></dd></dl><div class="Item"><a name="89739" class="autotag"> </a><b>AF_INET_STREAMS</b></div><dl class="margin"><dd><div class="Indent"><a name="95325" class="autotag"> </a>This address family provides access to the WindNet STREAMS socket library when it is used as the first parameter in the <b class="routine"><i class="routine">socket</i></b><b>( )</b> call. It is used when <b>DEFAULT_STREAMS_SOCKET</b> is <i class="emphasis">not defined</i>. </div><br></dd></dl></dd></dl><dl class="margin"><dd><p class="Body"><a name="76425" class="autotag"> </a>To configure your environment for BSD sockets, no new steps need be taken because <b>INCLUDE_BSD_SOCKETS</b> is defined in <b class="file">configAll.h</b> by default.</p><p class="Body"><a name="89755" class="autotag"> </a>To configure your environment for WindNet STREAMS sockets, define <b>INCLUDE_STREAMS_SOCKET</b> in <b class="file">configAll.h</b>. This constant alone does not make the default socket layer the WindNet STREAMS socket library; it only configures into VxWorks WindNet STREAMS sockets. To change the default, you must define <b>DEFAULT_STREAMS_SOCKET</b> in <b class="file">configAll.h</b>.</p><p class="Body"><a name="89754" class="autotag"> </a>The following examples show how to use WindNet STREAMS sockets and BSD sockets separately or concurrently:</p><p class="Body"><a name="76426" class="autotag"> </a>To use BSD sockets: </p></dd></dl><dl class="margin"><dd><p><ol class="List"><li value="1)"><a name="89899" class="autotag"> </a>When the BSD socket library is configured into VxWorks and is the default socket layer, use the following command:</li></ol></p><dl class="margin"><dd><pre class="Code2"><a name="89782" class="autotag">socket (AF_INET, SOCK_STREAM,0) </a></pre></dd></dl><p><ol class="List"><li value="2)"><a name="89900" class="autotag"> </a>When both libraries have been configured into VxWorks and WindNet STREAMS is the default socket layer, use the following command:</li></ol></p><dl class="margin"><dd><pre class="Code2"><a name="89837" class="autotag">socket (AF_INET_BSD, SOCK_STREAM,0) </a></pre></dd></dl></dd></dl><dl class="margin"><dd><p class="Body"><a name="89843" class="autotag"> </a>To use WindNet STREAMS sockets:</p></dd></dl><dl class="margin"><dd><p><ol class="List"><li value="3)"><a name="89911" class="autotag"> </a>When the WindNet STREAMS socket library is configured into VxWorks and WindNet STREAMS is the default socket layer, use the following command:</li></ol></p><dl class="margin"><dd><pre class="Code2"><a name="89912" class="autotag">socket (AF_INET, SOCK_STREAM,0) </a></pre></dd></dl><p><ol class="List"><li value="4)"><a name="89905" class="autotag"> </a>When both libraries are configured into VxWorks and BSD is the default socket layer, use the following command:</li></ol></p><dl class="margin"><dd><pre class="Code2"><a name="89853" class="autotag">socket (AF_INET_STREAMS, SOCK_STREAM, 0)</a></pre></dd></dl></dd></dl></dd></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="streams.doc7.html"><img border="0" alt="[Prev]" src="../../icons/prev.gif"></a><a href="streams.doc9.html"><img border="0" alt="[Next]" src="../../icons/next.gif"></a></p></body></html><!---This file generated April 10, 1998, 12:25PM PDTby WRS Documentation (jeff), Wind River Systems, Inc. conversion tool: Quadralay WebWorks Publisher 3.5.0 template: CSS Template, Jan 1998 - Jefro --->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -