gtpc1m4i | Transmission Control Protocol/Internet Protocol |
The writev function writes data on a socket with descriptor
s.
Format
#include <socket.h>
int writev(int s,
struct iovec *iov,
int iovcnt);
- s
- The socket descriptor.
- iov
- The pointer to an array of iovec buffers.
- iovcnt
- Number of buffers pointed to by the iov parameter.
Normal Return
If it succeeds, the function returns the number of bytes written from the
buffer.
Error Return
A return code equal to -1 indicates an error. You can get the
specific error code by calling sock_errno. See Appendix C, Socket Error Return Codes for more information about socket errors.
- Note:
- Unless otherwise stated in the description, the following error codes can be
returned for either TCP/IP offload support or TCP/IP native stack
support.
- Value
- Description
- SOCFAULT
- Using iov and iovcnt results in an attempt to access
memory outside the caller's address space. This error code is
returned only for TCP/IP offload support.
- SOCNOBUFS
- Buffer space is not available to send the message.
- SOCNOTSOCK
- The s parameter is not a valid socket descriptor.
- SOCWOULDBLOCK
- The s parameter is in nonblocking mode and no buffer space is
available to hold the message to be sent.
- SOCINVAL
- The iovcnt parameter was not valid or one of the fields in the
iov array was not valid.
- SOCMSGSIZE
- The message was too large to be sent. This error code is returned
only for TCP/IP native stack support.
- SOCNOTCONN
- The socket is not connected.
- EIBMIUCVERR
- An error occurred when the function call was sent to the offload
device. This error code is returned only for TCP/IP offload
support.
- E1052STATE
- The socket was closed because the system was in or cycling down to 1052
state.
- EINACT
- An offload device associated with the socket descriptor has been
disconnected. The socket is closed except in the following cases where
the API function call must be reissued to determine if the socket is
available:
This error code is returned only for TCP/IP offload support.
- ESYSTEMERROR
- A system error has occurred and closed the socket.
- SOCTIMEDOUT
- The operation timed out. The socket is still available. This
error code is returned only for TCP/IP native stack support.
Programming Considerations
- The data is gathered from the buffers specified by
iov[0]..iov[iovcnt-1].
The iovec structure is called by the writev
function.
struct iovec
{
char *iov_base;
int iov_len;
}
The iovec structure contains the following fields:
- Element
- Description
- iov_base
- Pointer to the buffer
- iov_len
- Length of the buffer.
The writev function applies only to connected sockets.
- This function 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
nonblocking mode, writev returns a -1 and sets
sock_errno to SOCWOULDBLOCK. See ioctl -- Perform Special Operations on Socket for a description of how to set nonblocking
mode.
- For sockets using TCP/IP native stack support, the send timeout value (the
SO_SNDTIMEO setsockopt option) determines how long to wait for
space to become available in the send buffer before the writev
function times out.
Examples
The following example sends data in two buffers of 10 bytes each.
#include <socket.h>
·
·
·
int bytes_sent;
int server_sock;
int wv_count;
char msg1[10] = "aaaaa";
char msg2[10] = "bbbbb";
struct iovec wv[2];
·
·
·
wv[0].iov_base = msg1;
wv[1].iov_base = msg2;
wv[0].iov_len = sizeof(msg1);
wv[1].iov_len = sizeof(msg2);
wv_count = 2;
bytes_sent = writev(server_sock,wv,wv_count);
Related Information