send function is like
write, but with the additional
flags flags. The possible values of flags are described
in Socket Data Options.
This function returns the number of bytes transmitted, or
failure. If the socket is nonblocking, then
write) can return after sending just part of the data.
See File Status Flags, for information about nonblocking mode.
Note, however, that a successful return value merely indicates that
the message has been sent without error, not necessarily that it has
been received without error.
errno error conditions are defined for this function:
- The socket argument is not a valid file descriptor.
- The operation was interrupted by a signal before any data was sent.
See Interrupted Primitives.
- The descriptor socket is not a socket.
- The socket type requires that the message be sent atomically, but the
message is too large for this to be possible.
- Nonblocking mode has been set on the socket, and the write operation
would block. (Normally
send blocks until the operation can be
- There is not enough internal buffer space available.
- You never connected this socket.
- This socket was connected but the connection is now broken. In this
send generates a
SIGPIPE signal first; if that
signal is ignored or blocked, or if its handler returns, then
send fails with
This function is defined as a cancellation point in multi-threaded
programs, so one has to be prepared for this and make sure that
allocated resources (like memory, files descriptors, semaphores or
whatever) are freed even if the thread is canceled.