Skip to content

Commit

Permalink
refactor(driver): remove one Result usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Dec 15, 2024
1 parent 24b971a commit c310c82
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 21 deletions.
8 changes: 4 additions & 4 deletions compio-driver/src/fusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ impl Driver {
}
}

pub fn handle(&self) -> io::Result<NotifyHandle> {
pub fn handle(&self) -> NotifyHandle {
let fuse = match &self.fuse {
FuseDriver::Poll(driver) => FuseNotifyHandle::Poll(driver.handle()?),
FuseDriver::IoUring(driver) => FuseNotifyHandle::IoUring(driver.handle()?),
FuseDriver::Poll(driver) => FuseNotifyHandle::Poll(driver.handle()),
FuseDriver::IoUring(driver) => FuseNotifyHandle::IoUring(driver.handle()),
};
Ok(NotifyHandle::from_fuse(fuse))
NotifyHandle::from_fuse(fuse)
}
}

Expand Down
7 changes: 2 additions & 5 deletions compio-driver/src/iocp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,8 @@ impl Driver {
Ok(())
}

pub fn handle(&self) -> io::Result<NotifyHandle> {
Ok(NotifyHandle::new(
self.port.handle(),
self.notify_overlapped.clone(),
))
pub fn handle(&self) -> NotifyHandle {
NotifyHandle::new(self.port.handle(), self.notify_overlapped.clone())
}
}

Expand Down
6 changes: 3 additions & 3 deletions compio-driver/src/iour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ impl Driver {
Ok(())
}

pub fn handle(&self) -> io::Result<NotifyHandle> {
pub fn handle(&self) -> NotifyHandle {
self.notifier.handle()
}
}
Expand Down Expand Up @@ -360,8 +360,8 @@ impl Notifier {
}
}

pub fn handle(&self) -> io::Result<NotifyHandle> {
Ok(NotifyHandle::new(self.fd.clone()))
pub fn handle(&self) -> NotifyHandle {
NotifyHandle::new(self.fd.clone())
}
}

Expand Down
2 changes: 1 addition & 1 deletion compio-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl Proactor {
}

/// Create a notify handle to interrupt the inner driver.
pub fn handle(&self) -> io::Result<NotifyHandle> {
pub fn handle(&self) -> NotifyHandle {
self.driver.handle()
}
}
Expand Down
4 changes: 2 additions & 2 deletions compio-driver/src/poll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ impl Driver {
Ok(())
}

pub fn handle(&self) -> io::Result<NotifyHandle> {
Ok(NotifyHandle::new(self.poll.clone()))
pub fn handle(&self) -> NotifyHandle {
NotifyHandle::new(self.poll.clone())
}
}

Expand Down
2 changes: 1 addition & 1 deletion compio-driver/tests/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn register_multiple() {
fn notify() {
let mut driver = Proactor::new().unwrap();

let handle = driver.handle().unwrap();
let handle = driver.handle();

let thread = std::thread::spawn(move || {
std::thread::sleep(Duration::from_secs(1));
Expand Down
6 changes: 1 addition & 5 deletions compio-runtime/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,7 @@ impl Runtime {
/// The caller should ensure the captured lifetime long enough.
pub unsafe fn spawn_unchecked<F: Future>(&self, future: F) -> Task<F::Output> {
let runnables = self.runnables.clone();
let handle = self
.driver
.borrow()
.handle()
.expect("cannot create notify handle of the proactor");
let handle = self.driver.borrow().handle();
let schedule = move |runnable| {
runnables.schedule(runnable, &handle);
};
Expand Down

0 comments on commit c310c82

Please sign in to comment.