writev

Jump to: navigation, search

Table of Contents >> Programmer's Reference


#include <trsocket.h>


int writev (
int socketDescriptor,
const struct iovec * iov,
int iovcnt
);


Function Description

writev() functions as a scatter write because the written data can be placed in multiple buffers. writev() attempts to write data to the socket socketDescriptor by gathering the data from into the iovcnt buffers specified by the members of the iov array: iov[0], iov[1], ..., iov[iovcnt-1].

The iovec structure contains the following members:

caddr_t  iov_base;
int      iov_len;

Each iovec entry specifies the base address and length of an area in memory from where data should be gathered. writev() always reads one buffer completely before proceeding to the next. On success, writev() return the number of bytes actually written; this number may be less than the total of all of the iov_len values if there is not enough space on the send queues.


Parameters

  • socketDescriptor
    The socket descriptor to write data to.
  • iov
    The list of buffers to gather and send the data from.
  • iovcnt
    The number of buffers in the list.


Return Values

  • > 0
    Number of bytes actually written.
  • TM_SOCKET_ERROR
    Failure.


Note Note: TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.

To retrieve the socket error the user must call tfGetSocketError(socketDescriptor).


Possible socket errors

  • TM_EBADF
    The socket descriptor is invalid.
  • TM_EINVAL
    One of the following:
  • iovcnt is 0 or less than zero.
  • The sum of iov_len values overflowed an integer.
  • TM_ENOBUFS
    Insufficient memory to complete the operation.
  • TM_EHOSTUNREACH
    No route to destination. (For non-TCP sockets.)
  • TM_ECONNREFUSED
    The socket received an ICMP destination unreachable message from the remote host. This typically means that the receiver is not listening on the remote port. (For non-TCP sockets.)
  • TM_EMSGSIZE
    The socket requires the message to be sent atomically, and the message was too long.
  • TM_EWOULDBLOCK
    The socket is marked as non-blocking and all of the data could not be written.
  • TM_ENOTCONN
    The socket is not connected.
  • TM_ESHUTDOWN
    The user has issued a tfWrite() shutdown call or a tfClose() call (TCP socket only).


Table of Contents >> Programmer's Reference