Sockets Programming Interfaces
3-28
This function can not be used with sockets of type SOCK_STREAM. When
used with sockets of type SOCK_STREAMNC, out of band data marks are
cleared.
The select call (fdSelect()) may be used to determine when more data arrives.
The flags argument to a recv() call can be one of the following flags:
MSG_DONTWAIT
requests that the operation not block when no data
is available.
MSG_WAITALL
requests that the operation block until data is avail-
able. Since blocking is the default behavior of a
standard socket, this flag only alters the behavior of
a “non-blocking” socket for this call.
Transmit Data to a Socket
send
Syntax
int send( int s, void *pbuf, int size, int flags );
Parameter(s)
s
Socket
pbuf
Data buffer holding data to transmit
size
Size of data
flags
Option flags
Return Value
If it succeeds, the function returns the number of bytes sent. Otherwise, a value
of –1 is returned and the function fdError() can be called to determine the error:
EBADF
The file descriptor (socket) is invalid.
ENOTSOCK
The file descriptor does not reference a socket.
ENOTCONN
The socket is connection oriented and not con-
nected.
EWOULDBLOCK
The socket is specified as non-blocking, or the
timeout has expired.
EMSGSIZE
The specified size exceeds the limit of the un-
derlying protocol.
ENOBUFS
Memory allocation failure while attempting to
send data.
EHOSTUNREACH
The remote host was unreachable.
Description
The send() function attempts to send data on a socket. It is used on a con-
nected sockets only (see connect()). The data to send is contained in the buffer
specified by pbuf, with a length specified by size. The options in flags can be
used to change the default behavior of the operation.
The functions returns the length of the data transmitted on successful comple-
tion.