examples: ignore interrupted syscalls for mio poll

While in general these examples shouldn't be written to handle errors,
the long-running MIO poll operation is especially prone to returning
interrupted syscall errors when a debugger is attached.

This commit updates each MIO example to ignore this class of error
rather than panicing, improving the debugging experience.
This commit is contained in:
Daniel McCarney 2024-02-13 12:56:25 -05:00
parent deffd3fa55
commit 1cdb10f8b4
2 changed files with 16 additions and 2 deletions

View File

@ -534,7 +534,14 @@ fn main() {
tlsclient.register(poll.registry());
loop {
poll.poll(&mut events, None).unwrap();
match poll.poll(&mut events, None) {
Ok(_) => {}
// Polling can be interrupted (e.g. by a debugger) - retry if so.
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => {
panic!("poll failed: {:?}", e)
}
}
for ev in events.iter() {
tlsclient.ready(ev);

View File

@ -702,7 +702,14 @@ fn main() {
let mut events = mio::Events::with_capacity(256);
loop {
poll.poll(&mut events, None).unwrap();
match poll.poll(&mut events, None) {
Ok(_) => {}
// Polling can be interrupted (e.g. by a debugger) - retry if so.
Err(e) if e.kind() == io::ErrorKind::Interrupted => continue,
Err(e) => {
panic!("poll failed: {:?}", e)
}
}
for event in events.iter() {
match event.token() {