select
select is used by an application to receive notifications of events that occur on one or more sockets of interest.
Syntax
int select(
int nfds,
fd_set *readfds,
fd_set *writefds,
fd_set *exceptfds,
const struct timeval *timeout
);
Parameters
nfds
Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.
readfds
The address of the descriptor set containing a set of sockets for which the application wishes to be notified when any of them becomes readable.
writefds
The address of the descriptor set containing a set of sockets for which the application wishes to be notified when any of them becomes writeable.
exceptfds
The address of the descriptor set containing a set of sockets for which the application wishes to be notified when any of them has a pending exception condition. Unlike in Windows, the only exception condition that can create a notification is when out-of-band data is available on a socket.
timeout
The address of a struct timeval which specifies how long the application is willing to block on the select call while waiting for a notification.
Return Value
If a timeout occurs and none of the selected events has occurred on any of the selected sockets, it returns 0 (zero).
For events that have occurred, it returns a positive integer representing the sum of the number of sockets in each fd_set.
If the function fails, it returns SOCKET_ERROR.
Use WSAGetLastError to retrieve a specific error code.
Remarks
The following macros are provided for manipulating socket descriptor sets:
| Macro | Description |
|---|---|
| FD_ZERO(&fdset); | Clears a socket descriptor set. |
| FD_SET(fd, &fdset); | Adds a socket descriptor fd to fdset. |
| FD_CLR(fd, &fdset); | Removes a socket descriptor fd from fdset. |
| FD_ISSET(fd, &fdset); | Is non-zero if fd is a member of fdset, zero otherwise. |
FD_SETSIZE is a maximum number of socket descriptors which could be used in a descriptor set. The default is 64.
The eRTOS TCP/IP Stack requires FD_SETSIZE to be greater than or equal to the number of sockets configured by the Stack. Setting it to a smaller value may result in a system crash.
Resolution of timeout depends on the HAL timer period. Note that timeout can sometimes occur within one HAL timer tick earlier than the requested time.
Requirements
| Minimum supported version | Header | Library |
|---|---|---|
|
eRTOS 1.0 SDK |
Winsock2.h | RtTcpipApi.lib |