The socket call receives data on a connected socket.
Syntax
#include <types.h> #include <sys\socket.h> int recv(s, buf, len, flags) int s; char *buf; int len; int flags;
Parameters
s
MSG_DONTWAIT
Description
This call receives data on a socket with descriptor s and stores it in the buffer pointed to by buf. The recv() call applies only to connected sockets. For information on how to use recv() with datagram and raw sockets, see Datagram or Raw Sockets.
The recv() call returns the length of the incoming data. If a datagram or sequenced packet is too long to fit in the buffer, the excess is discarded. No data is discarded for stream or sequenced packet sockets. If data is not available at the socket with descriptor s, the recv() call waits for data to arrive and blocks the caller, unless the socket is in nonblocking mode. See ioctl() for a description of how to set nonblocking mode.
Use the select() call to determine when more data arrives.
Return Values
When successful, the number of bytes of data received into the buffer is returned. The value 0 indicates that the connection is closed. The value -1 indicates an error. You can get the specific error code by calling sock_errno() or psock_errno().
Error Code
Related Calls
connect() getsockopt()
ioctl()
readv()
recvfrom()
recvmsg()
select()
send()
sendmsg()
sendto()
setsockopt()
shutdown()
sock_errno()
socket()
writev()