XSocket API  2.0
XIA Socket Library
Functions
Xrecv.c File Reference

Xrecv(), Xrecvfrom() - receive a message from a socket. More...

#include "Xsocket.h"

Functions

int Xrecv (int sockfd, void *rbuf, size_t len, int flags)
 Receive data from an Xsocket. More...
 
int Xrecvfrom (int sockfd, void *rbuf, size_t len, int flags, struct sockaddr *addr, socklen_t *addrlen)
 receives datagram data on an Xsocket More...
 

Function Documentation

int Xrecv ( int  sockfd,
void *  rbuf,
size_t  len,
int  flags 
)

The Xrecv() call is used to receive messages from a connected Xsocket.

If no data is available at the socket, Xrecv() will wait for a message to arrive, unless the socket is nonblocking (see Xfcntl()), in which case the value -1 is returned and errno is set to EAGAIN or EWOULDBLOCK. This call will return any data available, up to the requested amount, rather than waiting for receipt of the full amount requested.

An application can use Xselect() or Xpoll(), or to determine when more data arrives on a socket.

Parameters
sockfdThe socket to receive with
rbufwhere to put the received data
lenmaximum amount of data to receive. the amount of data returned may be less than len bytes.
flags(This is not currently used but is kept to be compatible with the standard send socket call).
Returns
the number of bytes returned, which may be less than the number requested by the caller
-1 on failure with errno set to an error compatible with the standard recv call.
int Xrecvfrom ( int  sockfd,
void *  rbuf,
size_t  len,
int  flags,
struct sockaddr *  addr,
socklen_t *  addrlen 
)

Xrecvfrom() retrieves data from an Xsocket of type XSOCK_DGRAM. Unlike the standard recvfrom API, it will not work with sockets of type XSOCK_STREAM.

If no data is available at the socket, Xrecvfrom() will wait for a message to arrive, unless the socket is nonblocking (see Xfcntl()), in which case the value -1 is returned and errno is set to EAGAIN or EWOULDBLOCK. This return any data available, up to the requested amount, rather than waiting for receipt of the full amount requested.

An application can use Xselect() or Xpoll(), or to determine when more data arrives on a socket.

Parameters
sockfdThe socket to receive with
rbufwhere to put the received data
lenmaximum amount of data to receive. The amount of data returned may be less than len bytes.
flags(This is not currently used but is kept to be compatible with the standard sendto socket call.
addrif non-NULL, filled with the address of the sender on success
addrlencontians the size of addr when called, replaced with the length of the received addr on return. addrlen MUST be set to the size of addr before calling Xrecvfrom() when addr is non-NULL. If addrlen is smaller than the length of the source DAG, the returned address is truncated and addrlen will contain length of the actual address.
Returns
number of bytes returned
-1 on failure with errno set.