select

select is used by an application to receive notifications of events that occur on one or more sockets of interest.

Syntax

Copy
int select(
    [in]        int nfds,
    [in, out]   fd_set *readfds,
    [in, out]   fd_set *writefds,
    [in, out]   fd_set *exceptfds,
    [in]        const struct timeval *timeout
);

Parameters

[in] nfds

Ignored. The nfds parameter is included only for compatibility with Berkeley sockets.

[in, out] readfds

The address of the descriptor set that contains a socket set for which the application wishes to be notified when any of them becomes readable.

[in, out] writefds

The address of the descriptor set that contains a socket set for which the application wishes to be notified when any of them becomes writeable.

[in, out] exceptfds

The address of the descriptor set that contains a socket set 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.

[in] timeout

The address of a timeval structure specifying 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.

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

SOCKET_ERROR if the function fails. Call 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.

You can use FD_SETSIZE, a maximum number of socket descriptors, in a descriptor set. The default is 64.

The 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

wRTOS 1.0 SDK

winsock2.h

RttcpipApi.lib

See also: