UDT Reference

UDT Reference: Functions

#### recv

The recv method reads certain amount of data into a local memory buffer.

int recv(
UDTSOCKET u,
char* buf,
int len,
int flags
);

##### Parameters

u
  [in] Descriptor identifying a connected socket.
buf
  [out] The buffer used to store incoming data.
len
  [in] Length of the buffer.
flags
  [in] Ignored. For compatibility only.

##### Return Value

On success, recv returns the actual size of received data. Otherwise UDT::ERROR is returned and specific error information can be retrieved by getlasterror. If UDT_RCVTIMEO is set to a positive value, zero will be returned if no data is received before the timer expires.

Error Name | Error Code | Comment
ECONNLOST | 2001 | connection has been broken and no data left in receiver buffer.
ENOCONN | 2002 | u is not connected.
EINVSOCK | 5004 | u is not an valid socket.
EDGRAMILL | 5010 | cannot use recv in SOCK_DGRAM mode.
EASYNCRCV | 6002 | u is non-blocking (UDT_RCVSYN = false) but no data is available.
ETIMEOUT | 6003 | Timeout on UDT_RCVTIMEO .

##### Description

The recv method reads certain amount of data from the protocol buffer. If there is not enough data in the buffer, recv only reads the available data in the protocol buffer and returns the actual size of data received. However, recv will never read more data than the buffer size indicates by len.

In blocking mode (default), recv waits until there is some data received into the receiver buffer. In non-blocking mode, recv returns immediately and returns error if no data available.

If UDT_RCVTIMEO is set and the socket is in blocking mode, recv only waits a limited time specified by UDT_RCVTIMEO option. If there is still no data available when the timer expires, error will be returned. UDT_RCVTIMEO has no effect for non-blocking socket.

##### See Also

send, sendfile, recvfile