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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       send — send a message on a socket
14

SYNOPSIS

16       #include <sys/socket.h>
17
18       ssize_t send(int socket, const void *buffer, size_t length, int flags);
19

DESCRIPTION

21       The send() function shall initiate transmission of a message  from  the
22       specified  socket to its peer. The send() function shall send a message
23       only when the socket is connected. If the socket is  a  connectionless-
24       mode  socket,  the  message  shall  be  sent  to the pre-specified peer
25       address.
26
27       The send() function takes the following arguments:
28
29       socket      Specifies the socket file descriptor.
30
31       buffer      Points to the buffer containing the message to send.
32
33       length      Specifies the length of the message in bytes.
34
35       flags       Specifies the type of message transmission. Values of  this
36                   argument are formed by logically OR'ing zero or more of the
37                   following flags:
38
39                   MSG_EOR       Terminates a record (if supported by the pro‐
40                                 tocol).
41
42                   MSG_OOB       Sends  out-of-band  data on sockets that sup‐
43                                 port out-of-band communications. The signifi‐
44                                 cance  and  semantics of out-of-band data are
45                                 protocol-specific.
46
47                   MSG_NOSIGNAL  Requests not to send the SIGPIPE signal if an
48                                 attempt  to send is made on a stream-oriented
49                                 socket  that  is  no  longer  connected.  The
50                                 [EPIPE] error shall still be returned.
51
52       The  length  of the message to be sent is specified by the length argu‐
53       ment. If the message is too long to pass through the underlying  proto‐
54       col, send() shall fail and no data shall be transmitted.
55
56       Successful  completion  of a call to send() does not guarantee delivery
57       of the message. A return value of −1  indicates  only  locally-detected
58       errors.
59
60       If  space is not available at the sending socket to hold the message to
61       be transmitted, and the socket file descriptor does not have O_NONBLOCK
62       set,  send()  shall  block  until  space  is available. If space is not
63       available at the sending socket to hold the message to be  transmitted,
64       and  the  socket file descriptor does have O_NONBLOCK set, send() shall
65       fail. The select() and poll() functions can be used to  determine  when
66       it is possible to send more data.
67
68       The  socket  in  use may require the process to have appropriate privi‐
69       leges to use the send() function.
70

RETURN VALUE

72       Upon successful completion, send() shall return  the  number  of  bytes
73       sent.  Otherwise,  −1  shall  be returned and errno set to indicate the
74       error.
75

ERRORS

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

EXAMPLES

134       None.
135

APPLICATION USAGE

137       If the socket argument refers to a connection-mode socket,  the  send()
138       function  is  equivalent  to sendto() (with any value for the dest_addr
139       and dest_len arguments, as they are  ignored  in  this  case).  If  the
140       socket  argument  refers  to  a socket and the flags argument is 0, the
141       send() function is equivalent to write().
142

RATIONALE

144       None.
145

FUTURE DIRECTIONS

147       None.
148

SEE ALSO

150       connect(),  getsockopt(),  poll(),   pselect(),   recv(),   recvfrom(),
151       recvmsg(),  sendmsg(),  sendto(),  setsockopt(),  shutdown(), socket(),
152       write()
153
154       The Base Definitions volume of POSIX.1‐2008, <sys_socket.h>
155
157       Portions of this text are reprinted and reproduced in  electronic  form
158       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
159       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
160       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
161       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
162       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
163       event of any discrepancy between this version and the original IEEE and
164       The  Open Group Standard, the original IEEE and The Open Group Standard
165       is the referee document. The original Standard can be  obtained  online
166       at http://www.unix.org/online.html .
167
168       Any  typographical  or  formatting  errors that appear in this page are
169       most likely to have been introduced during the conversion of the source
170       files  to  man page format. To report such errors, see https://www.ker
171       nel.org/doc/man-pages/reporting_bugs.html .
172
173
174
175IEEE/The Open Group                  2013                             SEND(3P)
Impressum