Skip to content

Commit

Permalink
server terminates by receiving the message "exit"
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Feb 13, 2024
1 parent da74a9b commit 929d622
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/miotcp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions examples/mioudp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 929d622

Please sign in to comment.