The select method queries one or more groups of UDT sockets.
Note: select is deprecated. Please use epoll instead, which is far more efficienct.
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. |
The UDSET is a structure to store the UDT socket descriptors. If should only be processed with the following macros.
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.
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