Skip to content

Commit

Permalink
Merge pull request #55 from Meziu/tweak/network-sockets-would-block
Browse files Browse the repository at this point in the history
network-sockets example: More gracefully handle ErrorKind::WouldBlock
  • Loading branch information
Meziu authored Apr 4, 2022
2 parents 2e80f8b + a2fc98c commit 40db202
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ctru-rs/examples/network-sockets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad};
use ctru::services::soc::Soc;

use std::io::{Read, Write};
use std::io::{self, Read, Write};
use std::net::{Shutdown, TcpListener};
use std::time::Duration;

Expand Down Expand Up @@ -37,7 +37,13 @@ fn main() {
let req_str = String::from_utf8_lossy(&buf);
println!("{}", req_str);
}
Err(e) => println!("Unable to read stream: {}", e),
Err(e) => {
if e.kind() == io::ErrorKind::WouldBlock {
println!("Note: Reading the connection returned ErrorKind::WouldBlock.")
} else {
println!("Unable to read stream: {}", e)
}
},
}

let response = b"HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n<html><body>Hello world</body></html>\r\n";
Expand Down

0 comments on commit 40db202

Please sign in to comment.