UDT Reference: UDT Functions |
The recv method receives certain size of data into a local memory buffer.
int recv( char *buf, int len, int flags, int *handle = NULL, UDT_MEM_ROUTINE routine = NULL, void* context = NULL ); |
On success, the actual size of received data is returned; Otherwise, UDT::ERROR is returned and the 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 Code | Comment |
---|---|
2001 |
connection broken before send is completed. |
2002 |
u is not connected. |
5004 |
u is an invalid UDT socket. |
5010 |
cannot use recv in SOCK_DGRAM mode. |
6002 |
no data is available to be received on a non-blocking socket. |
6003 | no buffer available for the non-blocking recv call. |
6004 |
an overlapped recv is in progress. |
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. On non-blocking socket, recv returns immediately, otherwise recv may wait until some data is available to read.
If the handle parameter is assigned, the recv method is enabled with overlapped IO processing. On blocking mode, UDT will wait until exact the same size of len data are received. On non-blocking mode, recv returns immediately but the successive data continue to be written into the user buffer. In either case, after the IO is completed, the function pointed by routine (if it is not NULL) will be called to process the buffer. Note that UDT does not duplicate the context parameter: it should remain valid until the routine is called, and it should be released (if necessary) by applications. The progress the overlapped recv can be queried by using getoverlappedresult.
Non-blocking overlapped receiving is exclusive.
If there is at least one non-blocking overlapped call in progress, all further
regular recv (non overlapped), recvfile, and
blocking overlapped recv will be rejected with error number 6004. This is
due to an implementation limitation.
Note that, UDT_RCVTIMEO
does NOT apply to overlapped recv.