Function Prototypes:
ssize_t recv (int sockfd, void *buf, size_t len, int flags);
The first parameter of the function formulates the receiving end socket descriptor;
The second parameter indicates a buffer, which is used to hold the data received by the RECV function;
The third parameter indicates the length of the buffer buf;
The fourth parameter is generally 0; (Flag bit)
The RECV function returns the number of bytes of its actual copy. If recv error in copy, then it returns SOCKET_ERROR; If the recv function waits for the protocol to receive data when the network is interrupted, then it returns 0;
The recv function is just copy data, and the real receive data is the protocol to complete.
The default recv function socket is blocked
There is no distinction between blocking and non-blocking recv return values, which are
<0 Error
=0 Connection off
>0 Receive data size,
Special: When the return value is <0 and (errno = = Eintr | | errno = = Ewouldblock | | errno = eagain), the connection is considered normal and continues to receive.
Just blocking mode recv will block the reception of data, non-blocking mode if no data will be returned, will not block the read, so need to loop read).
Return Description:
When executed successfully, returns the number of bytes received. 0 is returned when the other end is closed. The failed return -1,errno is set to one of the following values
Eagain: The socket is marked as non-blocking, and the receive operation is blocked or the receive time-out
Ebadf:sock is not a valid descriptive word.
Econnrefuse: Remote host blocking network connection
Efault: Error in memory space access
EINTR: Operation interrupted by signal
EINVAL: Invalid Parameter
ENOMEM: Low Memory
Enotconn: Socket associated with connection-oriented is not yet connected
Enotsock:sock index is not a socket
When the return value is 0 o'clock, the connection is closed normally;
Linux recv function return value analysis