The recv function receives incoming data that has been queued for the socket. This function can be used with both SOCK_STREAM and SOCK_DGRAM type sockets. It reads as much information as currently available up to the size of the buffer specified. In blocking mode, which is enabled if the system detects RTX environment, this functions waits for received data. In non blocking mode, you must call the recv function again if the error code SCK_EWOULDBLOCK is returned. The argument sock specifies a socket descriptor returned from a previous call to socket. The argument buf is a pointer to the application data buffer for storing the data to. If the available data is too large to fit in the supplied application buffer buf, excess bytes are discarded in case of SOCK_DGRAM sockets. For socket types SOCK_STREAM, the data is buffered internally so the application can retrieve all data by multiple calls of recv function. The argument len specifies the size of the application data buffer. The argument flags specifies the message flags: | Flag | Description |
|---|
| MSG_DONTWAIT | The function returns with error code SCK_EWOULDBLOCK instead of blocking the socket. | | MSG_PEEK | The function peeks at incoming data. The data is copied into the buffer, but is not removed from the input queue. |
The recv function is in the RL-TCPnet library. The prototype is defined in rtl.h. note - You must call the socket function before any other function calls to the BSD socket.
- If a negative number is returned, it represents an error code.
- The number of bytes actually read can be less than len.
|