The recvfrom function is used to receive data that has been queued for a socket. It is normally used to receive messages on SOCK_DGRAM socket type, but can also be used to receive a reliable, ordered stream of data on a connected SOCK_STREAM socket type. 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 recvfrom 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 recvfrom 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 argument from is a pointer to the SOCKADDR structure. If from is not NULL, the source IP address and port number of the datagram is filled in. The argument fromlen is a pointer to the address length. It should initially contain the amount of space pointed to by from. On return it contains the actual length of the address returned in bytes. The recvfrom 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.
|