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

📄 socklib.html

📁 Vxworks API操作系统和驱动程序设计API。压缩的HTML文件
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<html><head><!-- /vobs/wpwr/docs/vxworks/ref/sockLib.html - generated by refgen from sockLib.c --> <title> sockLib </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>sockLib</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>sockLib</strong> - generic socket library </p></blockquote><h4>ROUTINES</h4><blockquote><p><p><b><a href="./sockLib.html#socket">socket</a>(&nbsp;)</b>  -  open a socket<br><b><a href="./sockLib.html#bind">bind</a>(&nbsp;)</b>  -  bind a name to a socket<br><b><a href="./sockLib.html#listen">listen</a>(&nbsp;)</b>  -  enable connections to a socket<br><b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b>  -  accept a connection from a socket<br><b><a href="./sockLib.html#connect">connect</a>(&nbsp;)</b>  -  initiate a connection to a socket<br><b><a href="./sockLib.html#connectWithTimeout">connectWithTimeout</a>(&nbsp;)</b>  -  attempt socket connection within a specified duration<br><b><a href="./sockLib.html#sendto">sendto</a>(&nbsp;)</b>  -  send a message to a socket<br><b><a href="./sockLib.html#send">send</a>(&nbsp;)</b>  -  send data to a socket<br><b><a href="./sockLib.html#sendmsg">sendmsg</a>(&nbsp;)</b>  -  send a message to a socket<br><b><a href="./sockLib.html#recvfrom">recvfrom</a>(&nbsp;)</b>  -  receive a message from a socket<br><b><a href="./sockLib.html#recv">recv</a>(&nbsp;)</b>  -  receive data from a socket<br><b><a href="./sockLib.html#recvmsg">recvmsg</a>(&nbsp;)</b>  -  receive a message from a socket<br><b><a href="./sockLib.html#setsockopt">setsockopt</a>(&nbsp;)</b>  -  set socket options<br><b><a href="./sockLib.html#getsockopt">getsockopt</a>(&nbsp;)</b>  -  get socket options<br><b><a href="./sockLib.html#getsockname">getsockname</a>(&nbsp;)</b>  -  get a socket name<br><b><a href="./sockLib.html#getpeername">getpeername</a>(&nbsp;)</b>  -  get the name of a connected peer<br><b><a href="./sockLib.html#shutdown">shutdown</a>(&nbsp;)</b>  -  shut down a network connection<br><p></blockquote><h4>DESCRIPTION</h4><blockquote><p>This library provides UNIX BSD 4.4 compatible socket calls.  Use these calls to open, close, read, and write sockets. These sockets can join processes on the same CPU or on different CPUs between which there is anetwork connection.  The calling sequences of these routines are identical to their equivalents under UNIX BSD 4.4.<p>However, although the socket interface is compatible with VxWorks, the VxWorks environment does affect how you use sockets. Specifically, the globally accessible file descriptors available in the single address space world of VxWorks require that you take extra precautions when closing a file descriptor.<p>You must make sure that you do not close the file descriptor on which a task is pending during an <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b>. Although the <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b> on the closed file descriptor sometimes returns with an error, the <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b> can also fail to return at all. Thus, if you need to be able to close a socket connections file descriptor asynchronously, you may need to set up a semaphore-based locking mechanism that prevents the close while an <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b> is pending on the file descriptor.<p></blockquote><h4>ADDRESS FAMILY</h4><blockquote><p>VxWorks sockets support only the Internet Domain address family.  Use<b>AF_INET</b> for the <i>domain</i> argument in subroutines that require it.There is no support for the UNIX Domain address family.<p></blockquote><h4>IOCTL FUNCTIONS</h4><blockquote><p>Sockets respond to the following <b><a href="./ioLib.html#ioctl">ioctl</a>(&nbsp;)</b> functions.  These functions aredefined in the header files <b>ioLib.h</b> and <b>ioctl.h</b>.<dl><dt><b>FIONBIO</b><dd>Turns on/off non-blocking I/O.<pre>    on = TRUE;    status = ioctl (sFd, FIONBIO, &amp;on);</pre><dt><b>FIONREAD</b><dd>Reports the number of read-ready bytes available on the socket.  On the return of <b><a href="./ioLib.html#ioctl">ioctl</a>(&nbsp;)</b>, <i>bytesAvailable</i> has the number of bytes available to read from the socket.<pre>    status = ioctl (sFd, FIONREAD, &amp;bytesAvailable);</pre><dt><b>SIOCATMARK</b><dd>Reports whether there is out-of-band data to be read from the socket.  Onthe return of <b><a href="./ioLib.html#ioctl">ioctl</a>(&nbsp;)</b>, <i>atMark</i> is TRUE (1) if there is out-of-banddata.  Otherwise, it is FALSE (0).<pre>    status = ioctl (sFd, SIOCATMARK, &amp;atMark);</pre>To use this feature, include the following component:<b>INCLUDE_BSD_SOCKET</b><br> </dl></blockquote><h4>INCLUDE FILES</h4><blockquote><p><b>types.h</b>, <b>mbuf.h</b>, <b>socket.h</b>, <b>socketvar.h</b><p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./netLib.html#top">netLib</a></b>,<i>UNIX Network Programming , by W. Richard Stevens</i><hr><a name="socket"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>socket(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>socket(&nbsp;)</strong> - open a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int socket    (    int domain,               /* address family (for example, AF_INET) */    int type,                 /* SOCK_STREAM, SOCK_DGRAM, or SOCK_RAW */    int protocol              /* socket protocol (usually 0) */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine opens a socket and returns a socket descriptor.The socket descriptor is passed to the other socket routines to identify thesocket.  The socket descriptor is a standard I/O system file descriptor(fd) and can be used with the <b><a href="./ioLib.html#close">close</a>(&nbsp;)</b>, <b><a href="./ioLib.html#read">read</a>(&nbsp;)</b>, <b><a href="./ioLib.html#write">write</a>(&nbsp;)</b>, and <b><a href="./ioLib.html#ioctl">ioctl</a>(&nbsp;)</b> routines.<p>Available socket types include:<dl><dt><b>SOCK_STREAM</b><dd>Specifies a connection-based (stream) socket.<dt><b>SOCK_DGRAM</b><dd>Specifies a datagram (UDP) socket.<dt><b>SOCK_RAW</b><dd>Specifies a raw socket.</dl><p></blockquote><h4>RETURNS</h4><blockquote><p>A socket descriptor, or ERROR.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr><a name="bind"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>bind(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>bind(&nbsp;)</strong> - bind a name to a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS bind    (    int               s,      /* socket descriptor */    struct sockaddr * name,   /* name to be bound */    int               namelen /* length of name */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine associates a network address (also referred to as its "name")with a specified socket so that other processes can connect or send to it.When a socket is created with <b><a href="./sockLib.html#socket">socket</a>(&nbsp;)</b>, it belongs to an address familybut has no assigned name.<p></blockquote><h4>RETURNS</h4><blockquote><p><p>OK, or ERROR if there is an invalid socket, the address is eitherunavailable or in use, or the socket is already bound.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr><a name="listen"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>listen(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>listen(&nbsp;)</strong> - enable connections to a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS listen    (    int s,                    /* socket descriptor */    int backlog               /* number of connections to queue */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine enables connections to a socket.  It also specifies themaximum number of unaccepted connections that can be pending at one time(<i>backlog</i>).  After enabling connections with <b><a href="./sockLib.html#listen">listen</a>(&nbsp;)</b>, connections areactually accepted by <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b>.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK, or ERROR if the socket is invalid or unable to listen.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr><a name="accept"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>accept(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>accept(&nbsp;)</strong> - accept a connection from a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int accept    (    int               s,      /* socket descriptor */    struct sockaddr * addr,   /* peer address */    int *             addrlen /* peer address length */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine accepts a connection on a socket, and returns a new socketcreated for the connection.  The socket must be bound to an address with<b><a href="./sockLib.html#bind">bind</a>(&nbsp;)</b>, and enabled for connections by a call to <b><a href="./sockLib.html#listen">listen</a>(&nbsp;)</b>.  The <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b>routine dequeues the first connection and creates a new socket with thesame properties as <i>s</i>.  It blocks the caller until a connection ispresent, unless the socket is marked as non-blocking.<p>The <i>addrlen</i> parameter should be initialized to the size of the availablebuffer pointed to by <i>addr</i>.  Upon return, <i>addrlen</i> contains the size inbytes of the peer's address stored in <i>addr</i>.<p></blockquote><h4>WARNING</h4><blockquote><p>You must make sure that you do not close the file descriptor on which a task is pending during an <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b>. Although the <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b> on the closed file descriptor sometimes returns with an error, the <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b> can also fail to return at all. Thus, if you need to be able to close a socket connections file descriptor asynchronously, you may need to set up a semaphore-based locking mechanism that prevents the close while an <b><a href="./sockLib.html#accept">accept</a>(&nbsp;)</b> is pending on the file descriptor.<p></blockquote><h4>RETURNS</h4><blockquote><p>A socket descriptor, or ERROR if the call fails.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr><a name="connect"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries :  Routines</i></a></p></blockquote><h1>connect(&nbsp;)</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote>  <p><strong>connect(&nbsp;)</strong> - initiate a connection to a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS connect    (    int               s,      /* socket descriptor */    struct sockaddr * name,   /* addr of socket to connect */    int               namelen /* length of name, in bytes */    )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>If <i>s</i> is a socket of type <b>SOCK_STREAM</b>, this routine establishes a virtualcircuit between <i>s</i> and another socket specified by <i>name</i>.  If <i>s</i> is oftype <b>SOCK_DGRAM</b>, it permanently specifies the peer to which messagesare sent.  If <i>s</i> is of type <b>SOCK_RAW</b>, it specifies the raw socket uponwhich data is to be sent and received.  The <i>name</i> parameter specifies theaddress of the other socket.<p></blockquote><h4>NOTE</h4><blockquote><p>If a socket with type <b>SOCK_STREAM</b> is marked non-blocking, thisroutine will return ERROR with an error number of EINPROGRESS or EALREADYif a connection attempt is pending. A later call will return ERROR and setthe error number to EISCONN once the connection is established. Theconnection attempt must be repeated until that result occurs or untilthis routine establishes a connection immediately and returns OK.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK, or ERROR if the connection attempt does not complete.</blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b><hr>

⌨️ 快捷键说明

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