Chapter Contents

Previous

Next
recv

recv



Stores Messages from a Connected Socket

Portability: UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
CAUTION
PORTABILITY
RELATED FUNCTIONS


SYNOPSIS

#include <sys/types.h>
#include <sys/socket.h>

int recv(int s, void *buf, int len, int flags);


DESCRIPTION

recv receives messages on socket s and stores them in the buffer buf of length len . The socket must be connected or associated with a foreign peer via the connect function. If no messages are available, recv blocks the caller until a message arrives, unless the socket is set in non-blocking mode.

flags consists of the following:

MSG_OOB
processes a single byte of out-of-band data, if such data are present. If out-of-band data have been moved inline with the SO_OOBINLINE socket option, multiple bytes of data can be accessed, and the MSG_OOB option is not necessary.

MSG_PEEK
peeks at the incoming message. The data remain available for the next recv call.

read and recv behave identically if no flags have been set for recv .


RETURN VALUE

If recv succeeds, it returns the length of the message. If recv returns a 0 , it indicates that the connection is closed. Otherwise, it returns a -1 , and sets errno to indicate the type of error. It is possible for recv to return fewer bytes than are specified by len . For example, this condition occurs if the number of bytes in an incoming datagram is less than len . This is not an error.


CAUTION

recv discards excess bytes if the datagram is larger than the specified buffer.


PORTABILITY

recv is portable to other environments, including most UNIX systems, that implement BSD sockets.


RELATED FUNCTIONS

connect , getsockopt , recvfrom , recvmsg , send , sendmsg , sendto , setsockopt


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.