📄 send.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>send</title></head><body bgcolor="white"><basefont size="3"> <a name="send"></a> <a name="tag_03_641"></a><!-- send --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_641_01"></a>NAME</h4><blockquote>send - send a message on a socket</blockquote><h4><a name="tag_03_641_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/sys/socket.h.html">sys/socket.h</a>><br><br> ssize_t send(int</tt> <i>socket</i><tt>, const void *</tt><i>buffer</i><tt>, size_t</tt> <i>length</i><tt>, int</tt><i>flags</i><tt>);<br></tt></code></p></blockquote><h4><a name="tag_03_641_03"></a>DESCRIPTION</h4><blockquote><p>The <i>send</i>() function shall initiate transmission of a message from the specified socket to its peer. The <i>send</i>()function shall send a message only when the socket is connected (including when the peer of a connectionless socket has been setvia <a href="../functions/connect.html"><i>connect</i>()</a>).</p><p>The <i>send</i>() function takes the following arguments:</p><dl compact><dt><i>socket</i></dt><dd>Specifies the socket file descriptor.</dd><dt><i>buffer</i></dt><dd>Points to the buffer containing the message to send.</dd><dt><i>length</i></dt><dd>Specifies the length of the message in bytes.</dd><dt><i>flags</i></dt><dd>Specifies the type of message transmission. Values of this argument are formed by logically OR'ing zero or more of thefollowing flags: <dl compact><dt>MSG_EOR</dt><dd>Terminates a record (if supported by the protocol).</dd><dt>MSG_OOB</dt><dd>Sends out-of-band data on sockets that support out-of-band communications. The significance and semantics of out-of-band dataare protocol-specific.</dd></dl></dd></dl><p>The length of the message to be sent is specified by the <i>length</i> argument. If the message is too long to pass through theunderlying protocol, <i>send</i>() shall fail and no data shall be transmitted.</p><p>Successful completion of a call to <i>send</i>() does not guarantee delivery of the message. A return value of -1 indicates onlylocally-detected errors.</p><p>If space is not available at the sending socket to hold the message to be transmitted, and the socket file descriptor does nothave O_NONBLOCK set, <i>send</i>() shall block until space is available. If space is not available at the sending socket to holdthe message to be transmitted, and the socket file descriptor does have O_NONBLOCK set, <i>send</i>() shall fail. The <a href="../functions/select.html"><i>select</i>()</a> and <a href="../functions/poll.html"><i>poll</i>()</a> functions can be used todetermine when it is possible to send more data.</p><p>The socket in use may require the process to have appropriate privileges to use the <i>send</i>() function.</p></blockquote><h4><a name="tag_03_641_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>send</i>() shall return the number of bytes sent. Otherwise, -1 shall be returned and<i>errno</i> set to indicate the error.</p></blockquote><h4><a name="tag_03_641_05"></a>ERRORS</h4><blockquote><p>The <i>send</i>() function shall fail if:</p><dl compact><dt>[EAGAIN] or [EWOULDBLOCK]</dt><dd><br>The socket's file descriptor is marked O_NONBLOCK and the requested operation would block.</dd><dt>[EBADF]</dt><dd>The <i>socket</i> argument is not a valid file descriptor.</dd><dt>[ECONNRESET]</dt><dd>A connection was forcibly closed by a peer.</dd><dt>[EDESTADDRREQ]</dt><dd><br>The socket is not connection-mode and no peer address is set.</dd><dt>[EINTR]</dt><dd>A signal interrupted <i>send</i>() before any data was transmitted.</dd><dt>[EMSGSIZE]</dt><dd>The message is too large to be sent all at once, as the socket requires.</dd><dt>[ENOTCONN]</dt><dd>The socket is not connected or otherwise has not had the peer pre-specified.</dd><dt>[ENOTSOCK]</dt><dd>The <i>socket</i> argument does not refer to a socket.</dd><dt>[EOPNOTSUPP]</dt><dd>The <i>socket</i> argument is associated with a socket that does not support one or more of the values set in<i>flags</i>.</dd><dt>[EPIPE]</dt><dd>The socket is shut down for writing, or the socket is connection-mode and is no longer connected. In the latter case, and ifthe socket is of type SOCK_STREAM, the SIGPIPE signal is generated to the calling thread.</dd></dl><p>The <i>send</i>() function may fail if:</p><dl compact><dt>[EACCES]</dt><dd>The calling process does not have the appropriate privileges.</dd><dt>[EIO]</dt><dd>An I/O error occurred while reading from or writing to the file system.</dd><dt>[ENETDOWN]</dt><dd>The local network interface used to reach the destination is down.</dd><dt>[ENETUNREACH]</dt><dd><br>No route to the network is present.</dd><dt>[ENOBUFS]</dt><dd>Insufficient resources were available in the system to perform the operation.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_641_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_641_07"></a>APPLICATION USAGE</h4><blockquote><p>The <i>send</i>() function is equivalent to <a href="../functions/sendto.html"><i>sendto</i>()</a> with a null pointer<i>dest_len</i> argument, and to <a href="../functions/write.html"><i>write</i>()</a> if no flags are used.</p></blockquote><h4><a name="tag_03_641_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_641_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_641_10"></a>SEE ALSO</h4><blockquote><p><a href="connect.html"><i>connect</i>()</a> , <a href="getsockopt.html"><i>getsockopt</i>()</a> , <a href="poll.html"><i>poll</i>()</a> , <a href="recv.html"><i>recv</i>()</a> , <a href="recvfrom.html"><i>recvfrom</i>()</a> , <a href="recvmsg.html"><i>recvmsg</i>()</a> , <a href="select.html"><i>select</i>()</a> , <a href="sendmsg.html"><i>sendmsg</i>()</a> , <ahref="sendto.html"><i>sendto</i>()</a> , <a href="setsockopt.html"><i>setsockopt</i>()</a> , <a href="shutdown.html"><i>shutdown</i>()</a> , <a href="socket.html"><i>socket</i>()</a> , the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a></p></blockquote><h4><a name="tag_03_641_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -