Rust
Rust
Poll a Socket for Available Data
See more Socket/SSL/TLS Examples
Demonstrates Socket.PollDataAvailable, which performs a nonblocking check for readable activity and returns whether data or another read-ready condition is present.
Background. This lets an application check for incoming data without blocking, for example in an event loop that services multiple tasks.
Chilkat Rust Downloads
let socket = chilkat::Socket::new();
// Connect to the server using TLS.
let b_tls = true;
let max_wait_ms = 5000;
if socket.connect("example.com", 5000, b_tls, max_wait_ms).is_err() {
println!("{}", socket.last_error_text());
return;
}
// Perform a nonblocking check for readable data. Returns true when data or another read-ready
// condition is present, and false when nothing is immediately available.
let b_available = socket.poll_data_available();
if !b_available {
println!("No data is immediately available.");
} else {
println!("Data is available to read.");
}