Update io example

This commit is contained in:
Aode (lion) 2022-03-07 14:28:16 -06:00
parent e5c3b2c4bf
commit b5b6c19679

View file

@ -1,5 +1,6 @@
use foxtrot::{
io::{Nonblocking, ReadBytes, Readiness},
io::{Nonblocking, Readiness},
net::TcpListener,
Async,
};
use jitterbug::Executor;
@ -20,7 +21,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
foxtrot::block_on(executor.run_with(async move {
let executor = execu2r.clone();
executor.spawn(async move {
let mut listener = match Async::bind(([127, 0, 0, 1], 3456)).await {
let mut listener = match Async::<TcpListener>::bind(([127, 0, 0, 1], 3456)).await {
Ok(listener) => listener,
Err(_) => return,
};
@ -49,19 +50,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
if readiness.is_read() {
while let Some(buf) = ring_buf.for_reading() {
match stream.read_nonblocking(buf)? {
Nonblocking::Ready(ReadBytes::Read(n)) => {
let n: usize = n.into();
Nonblocking::Ready(n) if n > 0 => {
let should_break = n < buf.len();
ring_buf.advance_read(n);
if should_break {
break;
}
}
Nonblocking::Ready(ReadBytes::EOF) if ring_buf.is_empty() => {
break 'l2
}
Nonblocking::Ready(ReadBytes::EOF)
| Nonblocking::WouldBlock => break,
Nonblocking::Ready(_) if ring_buf.is_empty() => break 'l2,
Nonblocking::Ready(_) | Nonblocking::WouldBlock => break,
}
}