Use WouldBlock with network file
This commit is contained in:
@@ -8,7 +8,7 @@ use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, IpEndpoint, Ipv4Address}
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{BTreeMap, VecDeque};
|
use std::collections::{BTreeMap, VecDeque};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{Read, Write};
|
use std::io::{self, Read, Write};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -216,13 +216,15 @@ impl Smolnetd {
|
|||||||
let mut total_frames = 0;
|
let mut total_frames = 0;
|
||||||
loop {
|
loop {
|
||||||
let mut buffer = self.buffer_pool.borrow_mut().get_buffer();
|
let mut buffer = self.buffer_pool.borrow_mut().get_buffer();
|
||||||
let count = self.network_file
|
let count = match self.network_file.borrow_mut().read(&mut buffer) {
|
||||||
.borrow_mut()
|
Ok(count) => count,
|
||||||
.read(&mut buffer)
|
Err(err) => match err.kind() {
|
||||||
.map_err(|e| Error::from_io_error(e, "Failed to read from network file"))?;
|
io::ErrorKind::WouldBlock => break,
|
||||||
if count == 0 {
|
_ => return Err(
|
||||||
break;
|
Error::from_io_error(err, "Failed to read from network file")
|
||||||
}
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
buffer.resize(count);
|
buffer.resize(count);
|
||||||
self.input_queue.borrow_mut().push_back(buffer);
|
self.input_queue.borrow_mut().push_back(buffer);
|
||||||
total_frames += 1;
|
total_frames += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user