Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

soc_write(), soc_writev() (write, writev) - send a message from socket to socket

&pagelevel(3)&pagelevel

#include <sys.socket.h>

Kernighan-Ritchie-C:
int soc_write(s, buf, nbytes);

int s;
char *buf;
int nbytes;


#include <sys.types.h>

#include <sys.uio.h>

int soc_writev(s, iov, iovcnt)

int s;
struct iovec *iov;
int iovcnt;

ANSI-C:
int soc_write(int s, char* buf, int nbytes);
int soc_writev(int s, struct iovec* iov, int iovcnt);


Description

The soc_write() and soc_writev() functions support the following means of message transfer:

  • Messages from a stream socket s to another stream socket (AF_INET, AF_INET6)

  • Message from a connected datagram socket to another socket (AF_INET, AF_INET6)

  • From a socket s belonging to the AF_ISO address family to another socket belonging to the same address family.

soc_write() and soc_writev() can only be used if a connection between the two sockets has already been established.

For soc_write(), the buf parameter points to the first byte of the send buffer, and nbytes specifies the length (in bytes) of the send buffer.

For soc_writev(), the data to be sent is supplied in the vector with the elements iov[0], iov[1], ... ,iov[iovcnt-1]. The vector elements are objects of type struct iovec.
iovcnt indicates the number of vector elements.

The iovec structure is declared in <sys.uio.h> as follows:

struct iovec{
    caddr_t  iov_base;  /* buffer for auxiliary data */
    int      iovlen;    /* buffer length */
};

The address of the vector is passed in the iov parameter. Each vector element specifies the address and length of a storage area from which soc_writev() reads the data to be sent to the receiving socket s.

Return value

>=0:

If successful (number of bytes actually sent).

-1:

If errors occur. errno is set to indicate the error.

Errors indicated by errno

EBADF

The s parameter is not a valid descriptor.

ECONNRESET

The connection to the partner was interrupted (only with sockets of type SOCK_STREAM).

EINVAL

A parameter has specified an illegal value.

EIO

I/O error. The message could not be passed to the transport system.

ENETDOWN

The connection to the network is down.

ENOTCONN

No connection exists for the socket.

EOPNOTSUPP

The socket type is not supported. The socket is not of type SOCK_STREAM.

EPIPE

The socket is not activated for writing, or the socket is connection-oriented and the partner has shut the connection down.

EWOULDBLOCK

The socket is marked as non-blocking, and the requested operation would block.

Note

If the connection is established with a non-blocking socket then errno EINPROGRESS may occur on the next function call. This message indicates that the connection is not yet in a state which permits a data transfer phase.

See also

connect(), getsockopt(), recv(), select(), soc_read(), soc_readv(), socket()