5373 connect(3SOCKET) could talk about non-blocking mode
[unleashed.git] / usr / src / man / man3socket / send.3socket
blobb37df998f7cb1ce29be371cdb8aafab716204c1b
1 '\" te
2 .\" Copyright (C) 2009, Sun Microsystems, Inc. All Rights Reserved
3 .\" Copyright 1989 AT&T
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License. You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.
5 .\"  See the License for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with
6 .\" the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH SEND 3SOCKET "Aug 31, 2009"
8 .SH NAME
9 send, sendto, sendmsg \- send a message from a socket
10 .SH SYNOPSIS
11 .LP
12 .nf
13 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR... ]
14 #include <sys/types.h>
15 #include <sys/socket.h>
17 \fBssize_t\fR \fBsend\fR(\fBint\fR \fIs\fR, \fBconst void *\fR\fImsg\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIflags\fR);
18 .fi
20 .LP
21 .nf
22 \fBssize_t\fR \fBsendto\fR(\fBint\fR \fIs\fR, \fBconst void *\fR\fImsg\fR, \fBsize_t\fR \fIlen\fR, \fBint\fR \fIflags\fR,
23      \fBconst struct sockaddr *\fR\fIto\fR, \fBint\fR  \fItolen\fR);
24 .fi
26 .LP
27 .nf
28 \fBssize_t\fR \fBsendmsg\fR(\fBint\fR \fIs\fR, \fBconst struct msghdr *\fR\fImsg\fR, \fBint\fR \fIflags\fR);
29 .fi
31 .SH DESCRIPTION
32 .LP
33 The \fBsend()\fR, \fBsendto()\fR, and \fBsendmsg()\fR functions are used to
34 transmit a message to another transport end-point. The \fBsend()\fR function
35 can be used only when the socket is in a connected state. See
36 \fBconnect\fR(3SOCKET). The \fBsendto()\fR and \fBsendmsg()\fR functions can be
37 used at any time. The \fIs\fR socket is created with \fBsocket\fR(3SOCKET).
38 .sp
39 .LP
40 The address of the target is supplied by \fIto\fR with a \fItolen\fR parameter
41 used to specify the size. The length of the message is supplied by the
42 \fIlen\fR parameter. For socket types such as \fBSOCK_DGRAM\fR and
43 \fBSOCK_RAW\fR that require atomic messages, the error \fBEMSGSIZE\fR is
44 returned and the message is not transmitted when it is too long to pass
45 atomically through the underlying protocol. The same restrictions do not apply
46 to \fBSOCK_STREAM\fR sockets.
47 .sp
48 .LP
49 A return value \fB\(mi1\fR indicates locally detected errors. It does not imply
50 a delivery failure.
51 .sp
52 .LP
53 If the socket does not have enough buffer space available to hold a message,
54 the \fBsend()\fR function blocks the message, unless the socket has been placed
55 in non-blocking I/O mode (see \fBfcntl\fR(2)). The \fBselect\fR(3C) or
56 \fBpoll\fR(2) call can be used to determine when it is possible to send more
57 data.
58 .sp
59 .LP
60 The \fIflags\fR parameter is formed from the bitwise OR of zero or more of the
61 following:
62 .sp
63 .ne 2
64 .na
65 \fB\fBMSG_OOB\fR\fR
66 .ad
67 .RS 17n
68 Send \fBout-of-band\fR data on sockets that support this notion. The underlying
69 protocol must also support \fBout-of-band\fR data. Only \fBSOCK_STREAM\fR
70 sockets created in the \fBAF_INET\fR or the \fBAF_INET6\fR address family
71 support out-of-band data.
72 .RE
74 .sp
75 .ne 2
76 .na
77 \fB\fBMSG_DONTROUTE\fR\fR
78 .ad
79 .RS 17n
80 The \fBSO_DONTROUTE\fR option is turned on for the duration of the operation.
81 It is used only by diagnostic or routing programs.
82 .RE
84 .sp
85 .LP
86 See \fBrecv\fR(3SOCKET) for a description of the \fBmsghdr\fR structure.
87 .SH RETURN VALUES
88 .LP
89 Upon successful completion, these functions return the number of bytes sent.
90 Otherwise, they return \fB-1\fR and set \fBerrno\fR to indicate the error.
91 .SH ERRORS
92 .LP
93 The \fBsend()\fR, \fBsendto()\fR, and \fBsendmsg()\fR functions return errors
94 under the following conditions:
95 .sp
96 .ne 2
97 .na
98 \fB\fBEBADF\fR\fR
99 .ad
100 .RS 16n
101 \fIs\fR is not a valid file descriptor.
105 .ne 2
107 \fB\fBEINTR\fR\fR
109 .RS 16n
110 The operation was interrupted by delivery of a signal before any data could be
111 buffered to be sent.
115 .ne 2
117 \fB\fBEMSGSIZE\fR\fR
119 .RS 16n
120 The message is too large to be sent all at once (as the socket requires), or
121 the \fImsg_iovlen\fR member of the \fBmsghdr\fR structure pointed to by message
122 is less than or equal to 0 or is greater than {\fBIOV_MAX\fR}.
126 .ne 2
128 \fB\fBENOMEM\fR\fR
130 .RS 16n
131 Insufficient memory is available to complete the operation.
135 .ne 2
137 \fB\fBENOSR\fR\fR
139 .RS 16n
140 Insufficient STREAMS resources are available for the operation to complete.
144 .ne 2
146 \fB\fBENOTSOCK\fR\fR
148 .RS 16n
149 \fIs\fR is not a socket.
153 .ne 2
155 \fB\fBEWOULDBLOCK\fR\fR
157 .RS 16n
158 The socket is marked non-blocking and the requested operation would block.
159 \fBEWOULDBLOCK\fR is also returned when sufficient memory is not immediately
160 available to allocate a suitable buffer. In such a case, the operation can be
161 retried later.
165 .ne 2
167 \fB\fBECONNREFUSED\fR\fR
169 .RS 16n
170 The requested connection was refused by the peer. For conected IPv4 and IPv6
171 datagram sockets, this indicates that the system received an \fBICMP
172 Destination Port Unreachable\fR message from the peer in response to some prior
173 transmission.
178 The \fBsend()\fR and \fBsendto()\fR functions return errors under the following
179 conditions:
181 .ne 2
183 \fB\fBEINVAL\fR\fR
185 .RS 10n
186 The \fIlen\fR argument overflows a \fBssize_t\fR.
188 Inconsistent port attributes for system call.
193 The \fBsendto()\fR function returns errors under the following conditions:
195 .ne 2
197 \fB\fBEINVAL\fR\fR
199 .RS 10n
200 The value specified for the \fItolen\fR parameter is not the size of a valid
201 address for the specified address family.
205 .ne 2
207 \fB\fBEISCON\fR\fR
209 .RS 10n
210 A destination address was specified and the socket is already connected.
215 The \fBsendmsg()\fR function returns errors under the following conditions:
217 .ne 2
219 \fB\fBEINVAL\fR\fR
221 .RS 10n
222 The \fBmsg_iovlen\fR member of the \fBmsghdr\fR structure pointed to by
223 \fImsg\fR is less than or equal to \fB0\fR, or the sum of the \fIiov_len\fR
224 values in the \fBmsg_iov\fR array overflows a \fBssize_t\fR.
226 One of the \fIiov_len\fR values in the \fBmsg_iov\fR array member of the
227 \fBmsghdr\fR structure pointed to by \fImsg\fR is negative, or the sum of the
228 \fIiov_len\fR values in the \fBmsg_iov\fR array overflows a \fBssize_t\fR.
230 \fBmsg_iov\fR contents are inconsistent with port attributes.
235 The \fBsend()\fR function returns errors under the following conditions:
237 .ne 2
239 \fB\fBEPIPE\fR\fR
241 .RS 9n
242 The socket is shut down for writing, or the socket is connection-mode and is no
243 longer connected. In the latter case, if the socket is of type
244 \fBSOCK_STREAM\fR, the \fBSIGPIPE\fR signal is generated to the calling thread.
247 .SH ATTRIBUTES
249 See \fBattributes\fR(5) for descriptions of the following attributes:
254 box;
255 c | c
256 l | l .
257 ATTRIBUTE TYPE  ATTRIBUTE VALUE
259 Interface Stability     Committed
261 MT-Level        Safe
264 .SH SEE ALSO
266 \fBfcntl\fR(2), \fBpoll\fR(2), \fBwrite\fR(2), \fBconnect\fR(3SOCKET),
267 \fBgetsockopt\fR(3SOCKET), \fBrecv\fR(3SOCKET), \fBselect\fR(3C),
268 \fBsockaddr\fR(3SOCKET), \fBsocket\fR(3SOCKET), \fBsocket.h\fR(3HEAD),
269 \fBattributes\fR(5)