Browse Source

Merge pull request #55 from Meziu/tweak/network-sockets-would-block

network-sockets example: More gracefully handle ErrorKind::WouldBlock
pull/56/head
Meziu 3 years ago committed by GitHub
parent
commit
40db202e0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      ctru-rs/examples/network-sockets.rs

10
ctru-rs/examples/network-sockets.rs

@ -4,7 +4,7 @@ use ctru::services::apt::Apt;
use ctru::services::hid::{Hid, KeyPad}; use ctru::services::hid::{Hid, KeyPad};
use ctru::services::soc::Soc; use ctru::services::soc::Soc;
use std::io::{Read, Write}; use std::io::{self, Read, Write};
use std::net::{Shutdown, TcpListener}; use std::net::{Shutdown, TcpListener};
use std::time::Duration; use std::time::Duration;
@ -37,7 +37,13 @@ fn main() {
let req_str = String::from_utf8_lossy(&buf); let req_str = String::from_utf8_lossy(&buf);
println!("{}", req_str); 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"; 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";

Loading…
Cancel
Save