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

NAME

12       send — send a message on a socket
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

133       None.
134

APPLICATION USAGE

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

RATIONALE

143       None.
144

FUTURE DIRECTIONS

146       None.
147

SEE ALSO

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