Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lio/src/api/ops.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::unnecessary_lazy_evaluations)]

//! I/O operation definitions.
//!
//! This module contains all the typed operation structs that implement `TypedOp`.
Expand Down Expand Up @@ -1073,7 +1071,7 @@ impl<B: IoBufMutVec + std::marker::Send + Sync> OpModel for RecvFrom<B> {
let addr = result
.as_ref()
.ok()
.and_then(|_| self.core.from.as_ref())
.and(self.core.from.as_ref())
.and_then(|from| socket_addr_from_buf(from).ok());
OpResult::Done((result, buf, addr))
}
Expand Down
88 changes: 40 additions & 48 deletions lio/src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(clippy::never_loop)]

//! Filesystem resource types.

use std::{
Expand Down Expand Up @@ -514,57 +512,51 @@ impl RemoveDirAll {
}

fn advance(&mut self) -> OpResult<io::Result<()>> {
loop {
let Some(frame) = self.stack.last_mut() else {
self.state = RemoveDirAllState::Done;
return OpResult::Done(Ok(()));
};

if let Some(entry) = frame.entries.pop() {
match entry.file_type {
Some(FileType::Directory) => {
self.state = RemoveDirAllState::Opening {
op: ops::OpenAt::new(
frame.fd.clone(),
entry.name.clone(),
libc::O_RDONLY | libc::O_DIRECTORY,
0,
),
parent: frame.fd.clone(),
name: entry.name,
};
}
Some(_) => {
self.state = RemoveDirAllState::RemovingEntry {
op: ops::UnlinkAt::new(frame.fd.clone(), entry.name, 0),
};
}
None => {
self.state = RemoveDirAllState::Stating {
op: ops::Stat::new_at(
frame.fd.clone(),
entry.name.clone(),
false,
),
parent: frame.fd.clone(),
name: entry.name,
};
}
}
return OpResult::Again;
}
let Some(frame) = self.stack.last_mut() else {
self.state = RemoveDirAllState::Done;
return OpResult::Done(Ok(()));
};

if !frame.eof {
self.state = RemoveDirAllState::Reading { op: frame.next_read() };
return OpResult::Again;
if let Some(entry) = frame.entries.pop() {
match entry.file_type {
Some(FileType::Directory) => {
self.state = RemoveDirAllState::Opening {
op: ops::OpenAt::new(
frame.fd.clone(),
entry.name.clone(),
libc::O_RDONLY | libc::O_DIRECTORY,
0,
),
parent: frame.fd.clone(),
name: entry.name,
};
}
Some(_) => {
self.state = RemoveDirAllState::RemovingEntry {
op: ops::UnlinkAt::new(frame.fd.clone(), entry.name, 0),
};
}
None => {
self.state = RemoveDirAllState::Stating {
op: ops::Stat::new_at(frame.fd.clone(), entry.name.clone(), false),
parent: frame.fd.clone(),
name: entry.name,
};
}
}
return OpResult::Again;
}

let frame = self.stack.pop().expect("remove_dir_all stack missing frame");
self.state = RemoveDirAllState::RemovingDir {
op: ops::UnlinkAt::new(frame.parent, frame.name, libc::AT_REMOVEDIR),
};
if !frame.eof {
self.state = RemoveDirAllState::Reading { op: frame.next_read() };
return OpResult::Again;
}

let frame = self.stack.pop().expect("remove_dir_all stack missing frame");
self.state = RemoveDirAllState::RemovingDir {
op: ops::UnlinkAt::new(frame.parent, frame.name, libc::AT_REMOVEDIR),
};
OpResult::Again
}
}

Expand Down
14 changes: 7 additions & 7 deletions lio/tests/net_socket_datagram.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![allow(clippy::type_complexity)]
#![cfg(feature = "high")]

use std::{cell::RefCell, net::SocketAddr, rc::Rc};

type DatagramRecv = (std::io::Result<i32>, Vec<u8>, Option<SocketAddr>);
type DatagramRecvRx = Receiver<DatagramRecv>;
type DatagramRecvDone = Rc<RefCell<Option<(Vec<u8>, Option<SocketAddr>)>>>;

use lio::{
Lio,
api::Receiver,
Expand All @@ -14,15 +17,12 @@ struct ReceiverNode {
socket_rx: Option<Receiver<std::io::Result<Socket>>>,
socket: Option<Socket>,
bind_rx: Option<Receiver<std::io::Result<()>>>,
recv_rx:
Option<Receiver<(std::io::Result<i32>, Vec<u8>, Option<SocketAddr>)>>,
recv_done: Rc<RefCell<Option<(Vec<u8>, Option<SocketAddr>)>>>,
recv_rx: Option<DatagramRecvRx>,
recv_done: DatagramRecvDone,
}

impl ReceiverNode {
fn new(
recv_done: Rc<RefCell<Option<(Vec<u8>, Option<SocketAddr>)>>>,
) -> Self {
fn new(recv_done: DatagramRecvDone) -> Self {
Self {
socket_rx: None,
socket: None,
Expand Down
14 changes: 7 additions & 7 deletions lio/tests/net_udp.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![allow(clippy::type_complexity)]
#![cfg(feature = "high")]

use std::{cell::RefCell, net::SocketAddr, rc::Rc};

type DatagramRecv = (std::io::Result<i32>, Vec<u8>, Option<SocketAddr>);
type DatagramRecvRx = Receiver<DatagramRecv>;
type DatagramRecvDone = Rc<RefCell<Option<(Vec<u8>, Option<SocketAddr>)>>>;

use lio::{
Lio,
api::Receiver,
Expand Down Expand Up @@ -54,15 +57,12 @@ impl ReceiverNode {
struct DatagramReceiverNode {
socket_rx: Option<Receiver<std::io::Result<UdpSocket>>>,
socket: Option<UdpSocket>,
recv_rx:
Option<Receiver<(std::io::Result<i32>, Vec<u8>, Option<SocketAddr>)>>,
recv_done: Rc<RefCell<Option<(Vec<u8>, Option<SocketAddr>)>>>,
recv_rx: Option<DatagramRecvRx>,
recv_done: DatagramRecvDone,
}

impl DatagramReceiverNode {
fn new(
recv_done: Rc<RefCell<Option<(Vec<u8>, Option<SocketAddr>)>>>,
) -> Self {
fn new(recv_done: DatagramRecvDone) -> Self {
Self { socket_rx: None, socket: None, recv_rx: None, recv_done }
}

Expand Down