UDT Reference

UDT Reference: Functions

#### select

The select method queries one or more groups of UDT sockets.

Note: select is deprecated. Please use epoll instead, which is far more efficienct.

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

##### Parameters

nfds
  [in] Ignored. For compatibility only.
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] Ignored. For compatibility only.
timeout
  [in] The future time when this call should be timeout.

##### Return Value

If any of the read or write query is positive, select returns the number of UDT sockets that are read for read/write. If no socket is ready before timeout, zero is returned. If there is any error, UDT::ERROR is returned and the specific error information can be retrieved using getlasterror. The readfds and/or writefds will be updated to contain the ready sockets only.

Error Name | Error Code | Comment
EINVPARAM | 5003 | All three socket sets are empty or at least one of the socket is invalid.

##### Description

The UDSET is a structure to store the UDT socket descriptors. If should only be processed with the following macros.

UD_CLR(u, *set)
  Removes the descriptor u from set.
UD_ISSET(u, *set)
  Nonzero if u is a member of set; otherwise zero.
UD_SET(u, *set)
  Add descriptor u to set.
UD_ZERO(*set)
  Initialize set to an empty set.

The UDT descriptors sets originaly contains the sockets whose status is to be queried. When select returns, the descriptors sets only contain the sockets that are ready for IO. UD_ISSET can be used to check which one is ready.

readfds is used to detect if any socket in this set is available for reading (recv, recvmsg), for accepting a new connection (accept), or the associated connection is broken. writefds is used to detect if any socket in this set has available buffer for sending (send, sendmsg). Currently exceptfds is not used.

##### Example

The following example shows how to check if a UDT socket is available for recv.

UDTSOCKET u;
...
timeval tv;
UDSET readfds;
tv.tv_sec = 1;
tv.tv_usec = 0;
UD_ZERO(&readfds);
UD_SET(u, &readfds);
int res = UDT::select(0, &readfds, NULL, NULL, &tv);
if ((res != UDT::ERROR) && (UD_ISSET(u, &readfds)))
// read data from u.
else
// timeout or error

##### See Also

selectEx, epoll