xtd 0.2.0
Loading...
Searching...
No Matches

◆ select()

static size_t xtd::net::sockets::socket::select ( std::vector< socket > &  check_read,
std::vector< socket > &  check_write,
std::vector< socket > &  check_error,
int32  microseconds 
)
static

Determines the status of one or more sockets.

Parameters
check_readAn array of xtd::net::sockets::socket instances to check for readability.
check_writeAn array of xtd::net::sockets::socket instances to check for writability.
check_errorAn array of xtd::net::sockets::socket instances to check for errors.
microsecondsThe time-out value, in microseconds. A -1 value indicates an infinite time-out.
Returns
0 if the timeout expired; otherwise, the total number of sockets returned in the lists.
Exceptions
xtd::net::sockets::socket_exceptionAn error occurred when attempting to access the socket.
Remarks
xtd::net::sockets::socket::select is a static method that determines the status of one or more xtd::net::sockets::socket instances. You must place one or more sockets into an array before you can use the xtd::net::sockets::socket::select method. Check for readability by calling xtd::net::sockets::socket::select with the array as the check_read parameter. To check your sockets for writability, use the check_write parameter. For detecting error conditions, use check_error. After calling xtd::net::sockets::socket::select, the array will be filled with only those sockets that satisfy the conditions.
If you are in a listening state, readability means that a call to xtd::net::sockets::socket::accept will succeed without blocking. If you have already accepted the connection, readability means that data is available for reading. In these cases, all receive operations will succeed without blocking. Readability can also indicate whether the remote xtd::net::sockets::socket has shut down the connection; in that case a call to xtd::net::sockets::socket::receive will return immediately, with zero bytes returned.
xtd::net::sockets::socket::select returns when at least one of the sockets of interest (the sockets in the check_read, check_write, and check_error lists) meets its specified criteria, or the microseconds parameter is exceeded, whichever comes first. Setting microseconds to -1 specifies an infinite time-out.
If you make a nonblocking call to xtd::net::sockets::socket::connect, writability means that you have connected successfully. If you already have a connection established, writability means that all send operations will succeed without blocking.
If you have made a non-blocking call to xtd::net::sockets::socket::connect, the check_error parameter identifies sockets that have not connected successfully.
Use the xtd::net::sockets::socket::poll method if you only want to determine the status of a single xtd::net::sockets::socket.
Note
This method cannot detect certain kinds of connection problems, such as a broken network cable, or that the remote host was shut down ungracefully. You must attempt to send or receive data to detect these kinds of errors.
If you receive a xtd::net::sockets::socket_exception exception, use the xtd::net::sockets::socket_exception::error_code property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.