Microsoft Windows CE 3.0  

select

Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This function determines the status of one or more sockets, waiting if necessary.

int
select
(
int
nfds
,
fd_set
*
readfds
,
fd_set
*
writefds
,
fd_set
*
exceptfds
,
const
struct
timeval
*
timeout
);

Parameters

nfds
[in] Ignored; included only for compatibility with Berkeley sockets.
readfds
[in/out] Optional pointer to a set of sockets to be checked for readability.
writefds
[in/out] Optional pointer to a set of sockets to be checked for writability
exceptfds
[in/out] Optional pointer to a set of sockets to be checked for errors.
timeout
[in] Maximum time for selectto wait. NULL blocks indefinitely.

Return Values

Zero indicates that the time limit expired. SOCKET_ERROR indicates failure. To get a specific error value, call WSAGetLastError.

Remarks

The selectfunction is used to determine the status of one or more sockets. For each socket, the caller can request information on read, write, or error status. The set of sockets for which a given status is requested is indicated by an FD_SETstructure. The sockets contained within the FD_SETstructures must be associated with a single service provider. The selectfunction returns the number of sockets meeting the conditions. A set of macros is provided for manipulating an FD_SETstructure. These macros are compatible with those used in the Berkeley software, but the underlying representation is completely different.

The parameter readfdsidentifies the sockets that are to be checked for readability. If the socket is currently in the listenstate, it will be marked as readable if an incoming connection request has been received such that an acceptis guaranteed to complete without blocking. For other sockets, readability means that queued data is available for reading such that a call to recvor recvfromis guaranteed not to block.

For connection-oriented sockets, readability can also indicate that a request to close the socket has been received from the peer. If the virtual circuit was closed gracefully, and all data was received, then a recvwill return immediately with zero bytes read. If the virtual circuit was reset, then a recvwill complete immediately with an error value such as WSAECONNRESET.

The parameter writefdsidentifies the sockets that are to be checked for writability. If a socket is processing a connectcall (nonblocking), a socket is writable if the connection establishment successfully completes. If the socket is not processing a connectcall, writability means a sendor sendtoare guaranteed to succeed. However, they can block on a blocking socket if the lenparameter exceeds the amount of outgoing system buffer space available. It is not specified how long these guarantees can be assumed to be valid, particularly in a multithreaded environment.

The parameter exceptfdsidentifies the sockets that are to be checked for the presence of any exceptional error conditions.

Any two of the parameters, readfds, writefds, or exceptfds, can be given as NULL. At least one must be non-NULL, and any non-NULL descriptor set must contain at least one handle to a socket.

Summary: A socket will be identified in a particular set when selectreturns if:

readfds:
  • If listenhas been called and a connection is pending, acceptwill succeed
  • Connection has been closed/reset/terminated
    writefds:
    • If processing a connectcall (nonblocking), connection has succeeded
    • Data can be sent
      exceptfds:
      • If processing a connectcall (nonblocking), connection attempt failed

        Four macros are defined in the header file Winsock.h for manipulating and checking the descriptor sets. The variable FD_SETSIZEdetermines the maximum number of descriptors in a set. (The default value of FD_SETSIZEis 64, which can be modified by defining FD_SETSIZE to another value before including Winsock.h.) Internally, socket handles in an FD_SETstructure are not represented as bit flags as in Berkeley Unix. Their data representation is opaque. Use of these macros will maintain software portability between different socket environments. The macros to manipulate and check FD_SETcontents are:

        FD_CLR( s , * set )
        Removes the descriptor sfrom set.
        FD_ISSET( s , * set )
        Nonzero if sis a member of the set. Otherwise, zero.
        FD_SET( s , * set )
        Adds descriptor sto set.
        FD_ZERO(* set )
        Initializes the setto the NULL set.

        The parameter time-outcontrols how long the selectcan take to complete. If time-outis a null pointer, selectwill block indefinitely until at least one descriptor meets the specified criteria. Otherwise, time-outpoints to a TIMEVALstructure that specifies the maximum time that selectshould wait before returning. When selectreturns, the contents of the TIMEVALstructure are not altered. If TIMEVALis initialized to {0, 0}, selectwill return immediately; this is used to poll the state of the selected sockets. If selectreturns immediately, then the selectcall is considered nonblocking and the standard assumptions for nonblocking calls apply.

        Requirements

        Runs on Versions Defined in Include Link to
        Windows CE OS 1.0 and later Winsock.h    
        Note   This API is part of the complete Windows CE OS package as provided by Microsoft. The functionality of a particular platform is determined by the original equipment manufacturer (OEM) and some devices may not support this API.

        See Also

        accept, connect, recv, recvfrom, send, sendto, setsockopt, WSAStartup