📄 socklib.html
字号:
<a name="connectWithTimeout"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>connectWithTimeout( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>connectWithTimeout( )</strong> - attempt socket connection within a specified duration</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>STATUS connectWithTimeout ( int sock, /* socket descriptor */ struct sockaddr * adrs, /* addr of the socket to connect */ int adrsLen, /* length of the socket, in bytes */ struct timeval * timeVal /* time-out value */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>Use this routine as an alternative to <b><a href="./sockLib.html#connect">connect</a>( )</b> when your applicationrequires a shorter time out on a connection attempt. By design, a TCPconnection attempt times out after 75 seconds if unsuccessful. Thus, a blocking TCP socket <b><a href="./sockLib.html#connect">connect</a>( )</b> call might not return for 75 seconds. A <b><a href="./sockLib.html#connectWithTimeout">connectWithTimeout</a>( )</b> call lets you reduce this time out by scheduling an abort of the connection attempt if it is not successful before <i>timeVal</i>.However, <b><a href="./sockLib.html#connectWithTimeout">connectWithTimeout</a>( )</b> does not actually change the TCP timeoutvalue. Thus, you cannot use <b><a href="./sockLib.html#connectWithTimeout">connectWithTimeout</a>( )</b> to lengthen theconnection time out beyond the TCP default.<p>In all respects other than the time out value, a <b><a href="./sockLib.html#connectWithTimeout">connectWithTimeout</a>( )</b> call behaves exactly like <b><a href="./sockLib.html#connect">connect</a>( )</b>. Thus, if no application is listening for connections at the other end, <b><a href="./sockLib.html#connectWithTimeout">connectWithTimeout</a>( )</b> returns immediately just like <b><a href="./sockLib.html#connect">connect</a>( )</b>. If you specify a NULL pointer for <i>timeVal</i>, <b><a href="./sockLib.html#connectWithTimeout">connectWithTimeout</a>( )</b> behaves exactly like a <b><a href="./sockLib.html#connect">connect</a>( )</b> call.<p></blockquote><h4>RETURNS</h4><blockquote><p>OK, or ERROR if a new connection is not established before timeout.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b>, <b><a href="./sockLib.html#connect">connect</a>( )</b><hr><a name="sendto"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sendto( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sendto( )</strong> - send a message to a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sendto ( int s, /* socket to send data to */ caddr_t buf, /* pointer to data buffer */ int bufLen, /* length of buffer */ int flags, /* flags to underlying protocols */ struct sockaddr * to, /* recipient's address */ int tolen /* length of <i>to</i> sockaddr */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine sends a message to the datagram socket named by <i>to</i>. Thesocket <i>s</i> is received by the receiver as the sending socket.<p>The maximum length of <i>buf</i> is subject to the limits on UDP buffersize. See the discussion of <b>SO_SNDBUF</b> in the <b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b> manualentry.<p>You can OR the following values into the <i>flags</i> parameter with thisoperation:<p><dl><dt><b>MSG_OOB</b> (0x1)<dd>Out-of-band data.<p><dt><b>MSG_DONTROUTE</b> (0x4)<dd>Send without using routing tables.</dl><p></blockquote><h4>RETURNS</h4><blockquote><p>The number of bytes sent, or ERROR if the call fails.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b>, <b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b><hr><a name="send"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>send( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>send( )</strong> - send data to a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int send ( int s, /* socket to send to */ const char * buf, /* pointer to buffer to transmit */ int bufLen, /* length of buffer */ int flags /* flags to underlying protocols */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine transmits data to a previously established connection-based(stream) socket.<p>The maximum length of <i>buf</i> is subject to the limitson TCP buffer size; see the discussion of <b>SO_SNDBUF</b> in the<b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b> manual entry.<p>You may OR the following values into the <i>flags</i> parameter with thisoperation:<p><dl><dt><b>MSG_OOB</b> (0x1)<dd>Out-of-band data.<p><dt><b>MSG_DONTROUTE</b> (0x4)<dd>Send without using routing tables.</dl><p></blockquote><h4>RETURNS</h4><blockquote><p>The number of bytes sent, or ERROR if the call fails.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b>, <b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b>, <b><a href="./sockLib.html#sendmsg">sendmsg</a>( )</b><hr><a name="sendmsg"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>sendmsg( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>sendmsg( )</strong> - send a message to a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int sendmsg ( int sd, /* socket to send to */ struct msghdr * mp, /* scatter-gather message header */ int flags /* flags to underlying protocols */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine sends a message to a datagram socket. It may be used inplace of <b><a href="./sockLib.html#sendto">sendto</a>( )</b> to decrease the overhead of reconstructing themessage-header structure (<b>msghdr</b>) for each message.<p>For BSD 4.4 sockets a copy of the <i>mp</i>->msg_iov array will be made. Thisrequires a cluster from the network stack system pool of size <i>mp</i>->msg_iovlen * sizeof (struct iovec) or 8 bytes.<p></blockquote><h4>RETURNS</h4><blockquote><p>The number of bytes sent, or ERROR if the call fails.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b>, <b><a href="./sockLib.html#sendto">sendto</a>( )</b><hr><a name="recvfrom"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>recvfrom( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>recvfrom( )</strong> - receive a message from a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int recvfrom ( int s, /* socket to receive from */ char * buf, /* pointer to data buffer */ int bufLen, /* length of buffer */ int flags, /* flags to underlying protocols */ struct sockaddr * from, /* where to copy sender's addr */ int * pFromLen /* value/result length of <i>from</i> */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine receives a message from a datagram socket regardless ofwhether it is connected. If <i>from</i> is non-zero, the address of thesender's socket is copied to it. The value-result parameter <i>pFromLen</i>should be initialized to the size of the <i>from</i> buffer. On return,<i>pFromLen</i> contains the actual size of the address stored in <i>from</i>.<p>The maximum length of <i>buf</i> is subject to the limits on UDP buffersize; see the discussion of <b>SO_RCVBUF</b> in the <b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b> manualentry.<p>You may OR the following values into the <i>flags</i> parameter with thisoperation:<p><dl><dt><b>MSG_OOB</b> (0x1)<dd>Out-of-band data.<p><dt><b>MSG_PEEK</b> (0x2)<dd>Return data without removing it from socket.</dl><p></blockquote><h4>RETURNS</h4><blockquote><p>The number of number of bytes received, or ERROR if the call fails.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b>, <b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b><hr><a name="recv"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>recv( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>recv( )</strong> - receive data from a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int recv ( int s, /* socket to receive data from */ char * buf, /* buffer to write data to */ int bufLen, /* length of buffer */ int flags /* flags to underlying protocols */ )</pre></blockquote><h4>DESCRIPTION</h4><blockquote><p>This routine receives data from a connection-based (stream) socket.<p>The maximum length of <i>buf</i> is subject to the limits on TCP buffersize; see the discussion of <b>SO_RCVBUF</b> in the <b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b> manualentry.<p>You may OR the following values into the <i>flags</i> parameter with thisoperation:<p><dl><dt><b>MSG_OOB</b> (0x1)<dd>Out-of-band data.<p><dt><b>MSG_PEEK</b> (0x2)<dd>Return data without removing it from socket.</dl><p></blockquote><h4>RETURNS</h4><blockquote><p>The number of bytes received, or ERROR if the call fails.<p></blockquote><h4>SEE ALSO</h4><blockquote><p><b><a href="./sockLib.html#top">sockLib</a></b>, <b><a href="./sockLib.html#setsockopt">setsockopt</a>( )</b><hr><a name="recvmsg"></a><p align=right><a href="rtnIndex.htm"><i>OS Libraries : Routines</i></a></p></blockquote><h1>recvmsg( )</h1> <blockquote></a></blockquote><h4>NAME</h4><blockquote> <p><strong>recvmsg( )</strong> - receive a message from a socket</p></blockquote><h4>SYNOPSIS</h4><blockquote><p><pre>int recvmsg ( int sd, /* socket to receive from */ struct msghdr * mp, /* scatter-gather message header */ int flags /* flags to underlying protocols */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -