1SEND(P)                    POSIX Programmer's Manual                   SEND(P)
2
3
4

NAME

6       send - send a message on a socket
7

SYNOPSIS

9       #include <sys/socket.h>
10
11       ssize_t send(int socket, const void *buffer, size_t length, int flags);
12
13

DESCRIPTION

15       The  send()  function shall initiate transmission of a message from the
16       specified socket to its peer. The send() function shall send a  message
17       only when the socket is connected (including when the peer of a connec‐
18       tionless socket has been set via connect()).
19
20       The send() function takes the following arguments:
21
22       socket Specifies the socket file descriptor.
23
24       buffer Points to the buffer containing the message to send.
25
26       length Specifies the length of the message in bytes.
27
28       flags  Specifies the type of message transmission. Values of this argu‐
29              ment  are formed by logically OR'ing zero or more of the follow‐
30              ing flags:
31
32       MSG_EOR
33              Terminates a record (if supported by the protocol).
34
35       MSG_OOB
36              Sends out-of-band data on sockets that support out-of-band  com‐
37              munications.  The significance and semantics of out-of-band data
38              are protocol-specific.
39
40
41
42       The length of the message to be sent is specified by the  length  argu‐
43       ment.  If the message is too long to pass through the underlying proto‐
44       col, send() shall fail and no data shall be transmitted.
45
46       Successful completion of a call to send() does not  guarantee  delivery
47       of  the  message.  A return value of -1 indicates only locally-detected
48       errors.
49
50       If space is not available at the sending socket to hold the message  to
51       be transmitted, and the socket file descriptor does not have O_NONBLOCK
52       set, send() shall block until space is  available.   If  space  is  not
53       available  at the sending socket to hold the message to be transmitted,
54       and the socket file descriptor does have O_NONBLOCK set,  send()  shall
55       fail.  The  select() and poll() functions can be used to determine when
56       it is possible to send more data.
57
58       The socket in use may require the process to  have  appropriate  privi‐
59       leges to use the send() function.
60

RETURN VALUE

62       Upon  successful  completion,  send()  shall return the number of bytes
63       sent. Otherwise, -1 shall be returned and errno  set  to  indicate  the
64       error.
65

ERRORS

67       The send() function shall fail if:
68
69       EAGAIN or EWOULDBLOCK
70
71              The  socket's  file  descriptor  is  marked  O_NONBLOCK  and the
72              requested operation would block.
73
74       EBADF  The socket argument is not a valid file descriptor.
75
76       ECONNRESET
77              A connection was forcibly closed by a peer.
78
79       EDESTADDRREQ
80
81              The socket is not connection-mode and no peer address is set.
82
83       EINTR  A signal interrupted send() before any data was transmitted.
84
85       EMSGSIZE
86              The message is too large to be sent all at once, as  the  socket
87              requires.
88
89       ENOTCONN
90              The  socket  is  not connected or otherwise has not had the peer
91              pre-specified.
92
93       ENOTSOCK
94              The socket argument does not refer to a socket.
95
96       EOPNOTSUPP
97              The socket argument is associated with a socket  that  does  not
98              support one or more of the values set in flags.
99
100       EPIPE  The  socket  is  shut down for writing, or the socket is connec‐
101              tion-mode and is no longer connected. In the latter case, and if
102              the  socket is of type SOCK_STREAM, the SIGPIPE signal is gener‐
103              ated to the calling thread.
104
105
106       The send() function may fail if:
107
108       EACCES The calling process does not have the appropriate privileges.
109
110       EIO    An I/O error occurred while reading from or writing to the  file
111              system.
112
113       ENETDOWN
114              The  local  network  interface  used to reach the destination is
115              down.
116
117       ENETUNREACH
118
119              No route to the network is present.
120
121       ENOBUFS
122              Insufficient resources were available in the system  to  perform
123              the operation.
124
125
126       The following sections are informative.
127

EXAMPLES

129       None.
130

APPLICATION USAGE

132       The  send()  function  is  equivalent  to  sendto() with a null pointer
133       dest_len argument, and to write() if no flags are used.
134

RATIONALE

136       None.
137

FUTURE DIRECTIONS

139       None.
140

SEE ALSO

142       connect() , getsockopt() , poll() , recv() , recvfrom() ,  recvmsg()  ,
143       select()  , sendmsg() , sendto() , setsockopt() , shutdown() , socket()
144       , the Base Definitions volume of IEEE Std 1003.1-2001, <sys/socket.h>
145
147       Portions of this text are reprinted and reproduced in  electronic  form
148       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
149       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
150       Specifications  Issue  6,  Copyright  (C) 2001-2003 by the Institute of
151       Electrical and Electronics Engineers, Inc and The Open  Group.  In  the
152       event of any discrepancy between this version and the original IEEE and
153       The Open Group Standard, the original IEEE and The Open Group  Standard
154       is  the  referee document. The original Standard can be obtained online
155       at http://www.opengroup.org/unix/online.html .
156
157
158
159IEEE/The Open Group                  2003                              SEND(P)
Impressum