From 8484aa614d76d81953ca4831ff00f8b29664dac9 Mon Sep 17 00:00:00 2001 From: Mark Drobnak Date: Sun, 3 Apr 2022 17:38:10 -0700 Subject: [PATCH 1/2] network-sockets example: More gracefully handle ErrorKind::WouldBlock --- ctru-rs/examples/network-sockets.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ctru-rs/examples/network-sockets.rs b/ctru-rs/examples/network-sockets.rs index 2172d81..ae488eb 100644 --- a/ctru-rs/examples/network-sockets.rs +++ b/ctru-rs/examples/network-sockets.rs @@ -1,3 +1,4 @@ +use std::io; use ctru::console::Console; use ctru::gfx::Gfx; use ctru::services::apt::Apt; @@ -37,7 +38,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\nHello world\r\n"; From a2fc98cb5cd8d6b556d41e31e405e1101fb14984 Mon Sep 17 00:00:00 2001 From: Mark Drobnak Date: Sun, 3 Apr 2022 17:39:52 -0700 Subject: [PATCH 2/2] Update imports --- ctru-rs/examples/network-sockets.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ctru-rs/examples/network-sockets.rs b/ctru-rs/examples/network-sockets.rs index ae488eb..ac8953d 100644 --- a/ctru-rs/examples/network-sockets.rs +++ b/ctru-rs/examples/network-sockets.rs @@ -1,11 +1,10 @@ -use std::io; use ctru::console::Console; use ctru::gfx::Gfx; 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;