diff --git a/examples/miotcp/src/main.rs b/examples/miotcp/src/main.rs index 6862b32ce..67a07194d 100644 --- a/examples/miotcp/src/main.rs +++ b/examples/miotcp/src/main.rs @@ -170,6 +170,9 @@ fn handle_connection_event( let received_data = &received_data[..bytes_read]; if let Ok(str_buf) = from_utf8(received_data) { println!("Received data: {}", str_buf.trim_end()); + if str_buf.trim_end() == "exit" { + std::process::exit(0); + } } else { println!("Received (none UTF-8) data: {:?}", received_data); } diff --git a/examples/mioudp/src/main.rs b/examples/mioudp/src/main.rs index d0cce7143..2e85f8c6a 100644 --- a/examples/mioudp/src/main.rs +++ b/examples/mioudp/src/main.rs @@ -7,6 +7,7 @@ use hermit as _; use log::warn; use mio::{Events, Interest, Poll, Token}; use std::io; +use std::str::from_utf8; // A token to allow us to identify which event is for the `UdpSocket`. const UDP_SOCKET: Token = Token(0); @@ -63,6 +64,11 @@ fn main() -> io::Result<()> { Ok((packet_size, source_address)) => { // Echo the data. socket.send_to(&buf[..packet_size], source_address)?; + if let Ok(str_buf) = from_utf8(&buf) { + if str_buf.trim_end() == "exit" { + std::process::exit(0); + } + } } Err(e) if e.kind() == io::ErrorKind::WouldBlock => { // If we get a `WouldBlock` error we know our socket