UDT Reference: UDT Functions

select

The select method queries the status of a group of UDT sockets.

int select(
  int nfds,
  UDSET *readfds,

  UDSET *writefds,
  UDSET *exceptfds,

  const struct timeval *timeout 
);

Parameters

nfds
[in] Ignored. For compatibility purpose 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 purpose only.
timeout
[in] Maximum time for select to wait, provided in the form of a timeval structure. Set the timeout parameter to NULL for blocking operation.

Return Values

If any of the read/write/exception queries is positive, select returns the number of UDT sockets that are ready; If no socket is ready before timeout, 0 is returned; If there is any error, UDT::ERROR is returned and the specific error information can be retrieved by getlasterror.

Error Code Comment

5003

all the three UDT socket descriptor sets are NULL, or at least one of them contains an invalid socket descriptor.

Description

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

UD_CLR(u, *set)
Removes the descriptor s from set.
UD_ISSET(u, *set)
Nonzero if s is a member of the set. Otherwise, zero.
UD_SET(u, *set)
Adds descriptor s to set.
UD_ZERO(*set)
Initializes the set to the NULL set.

The UDT descriptors sets originally contain the sockets whose status are to be queried. When select returns successfully (returned value is greater than 0), the descriptors sets only contain the sockets that are ready. UD_ISSET is used to query which one is ready.

readfds detects if any socket in this sets is available for reading (recv), for accepting a new connection (accept), or the connection is broken. writefds detects if any socket in this sets has available buffer for sending (send). exceptfds is currently not used.

Example

The following codes show how to send a whole file to the remote node using UDT:

UDTSOCKET u;

...

 

timeval tv;
UDSET readfds;

tv.tv_sec = 1;
tv.tv_usec = 0;

UD_ZERO(&readfds);
UD_SET(u, &readfds);

int res = select(0, &readfds, NULL, NULL, &tv);

if ((res != UDT_ERROR) && (UD_ISSET(u, &readfds)))
   // read data from u.
else
   // timeout or error

See Also

send, recv