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 that contains 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 that contains 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 that contains 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

0 if a timeout occurs and none of the selected events has occurred on any of the selected sockets, or

A positive integer which is the sum of the number of sockets in each fd_set for which events have occurred, or

SOCKET_ERROR if the function fails

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 RTX64 RT-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 RTX64 2013
Header Winsock2.h
Library RtTcpip.lib

See also: