The socket call writes data from a set of specified buffers on a socket.
Syntax
#include <types.h> #include <sys/uio.h> int writev(s, iov, iovcnt) int s; struc iovec *iov; int iovcnt;
Parameters
s
Description
This call writes data on a socket with descriptor s. The data is gathered from the buffers specified by iov[0]...iov[iovcnt-1]. The iovec structure is defined in <SYS/UIO.H> and contains the following fields:
Field
This call writes iov_len bytes of data. If there is not enough available buffer space to hold the socket data to be transmitted and the socket is in blocking mode, writev() blocks the caller until additional buffer space becomes available. If the socket is in a nonblocking mode, writev() returns -1 and sets return code to SOCEWOULDBLOCK. See ioctl() for a description of how to set nonblocking mode.
TCP/IP alters iov_base and iov_len for each element in the input struct iovec array. iov_base will point to the next character of the processed (sent or received) data on the original buffer, and iov_len will become (input value - processed length). Thus if only partial data has been sent or received and the application expects more data to send or receive, it can pass the same iovec back in a subsequent call.
For datagram sockets, this call sends the entire datagram, provided the datagram fits into the protocol buffers. Stream sockets act like streams of information with no boundaries separating data. For example, if an application sends 1000 bytes, each call to this function can send 1 byte, 10 bytes, or the entire 1000 bytes. For a stream socket, an application can place this call in a loop, calling this function until all data has been sent.
Return Values
When successful, the number of bytes of data written is returned. Successful completion does not guarantee the data is written. The return value -1 indicates an error was detected on the sending side of the connection. You can get the specific error code by calling sock_errno() or psock_errno().
sock_errno() Value
Related Calls
connect() getsockopt()
ioctl()
readv()
recv()
recvfrom()
recvmsg()
select()
send()
sendmsg()
sendto()
setsockopt()
sock_errno()
socket()