|
Description
The write() and writev() functions send messages from one socket to another. write() and writev() can only be used with a socket over which a connection is set up.
More general information on this function is available in the manual "C Library Functions for POSIX Applications".
The s parameter designates the socket over which the message is sent.
For write(), the buf parameter points to the first byte of the send buffer, and len specifies the length of the message in the send buffer in bytes.
For writev(), the data to be sent is supplied in the vector with the members iov[0] to iov[iovcnt-1]. The vector members are objects of the type struct iovec. The address of the vector is passed in the iov parameter. Each vector member contains the address and length of a storage area from which writev() reads the data to be sent.
The struct iovec structure is declared as follows:
struct iovec { caddr_t iov_base; /* buffer for data */ size_t iov_len; /* length of buffer */ };
iovcnt indicates the number of vector members.
If the message is too long to be transported completely by the underlying protocol level, error EMSGSIZE is returned and the message is not transferred.
If the process which calls write() and writev() receives a signal before any send data is buffered, the function concerned is called again in a standard case. The function is not called again if the calling process has specified with sigaction() to interrupt these function calls (see also the manual "C Library Functions for POSIX Applications").
Return value
Number of bytes actually sent:
If successful.
-1:
If errors occur. errno is set to indicate the error. The descriptor sets are then not changed.
Errors
EBADF
The s parameter is not a valid descriptor.
ECONNRESET
The connection to the partner was interrupted (only with type SOCK_STREAM sockets).
EFAULT
The data is to be sent from a non-existent or protected part of the process address range.
EINTR
The calling process received a signal before any data could be buffered for sending. The setting to interrupt the function call and not repeat it is active.
EINVAL
A parameter specifies an illegal value.
EMSGSIZE
The message is too long to be sent in one piece.
ENETDOWN
The connection to the network is down.
ENOBUFS
The system could not provide an internal buffer. The operation can succeed if memory becomes free again. The output queue for a network interface is full. This generally leads to the interface stopping sending, but can also be due to a temporary jam.
ENOTCONN
No connection exists for the socket.
ENOTSOCK
Descriptor s references a file and not a socket.
EPIPE
The socket is not activated for writing or the socket is connection-oriented and the partner has shut the connection down.
If the socket is of type SOCK_STREAM, the SIGPIPE signal is generated for the calling process.
EWOULDBLOCK
The socket is marked as non-blocking and the requested operation would block.
See also
connect(), getsockopt(), recv(), socket(), fcntl(), select(), write()