Skip to content

Commit

Permalink
Merge pull request #306 from Berrysoft/fix/notify-handle-create
Browse files Browse the repository at this point in the history
fix(driver,poll,iour): use Arc::clone instead of try_clone
  • Loading branch information
Berrysoft authored Oct 21, 2024
2 parents 39082ce + b0d82a4 commit 464552d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion compio-driver/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "compio-driver"
version = "0.5.0"
version = "0.5.1"
description = "Low-level driver for compio"
categories = ["asynchronous"]
keywords = ["async", "iocp", "io-uring"]
Expand Down
10 changes: 5 additions & 5 deletions compio-driver/src/iour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ fn timespec(duration: std::time::Duration) -> Timespec {

#[derive(Debug)]
struct Notifier {
fd: OwnedFd,
fd: Arc<OwnedFd>,
}

impl Notifier {
/// Create a new notifier.
fn new() -> io::Result<Self> {
let fd = syscall!(libc::eventfd(0, libc::EFD_CLOEXEC | libc::EFD_NONBLOCK))?;
let fd = unsafe { OwnedFd::from_raw_fd(fd) };
Ok(Self { fd })
Ok(Self { fd: Arc::new(fd) })
}

pub fn clear(&self) -> io::Result<()> {
Expand All @@ -342,7 +342,7 @@ impl Notifier {
}

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

Expand All @@ -354,11 +354,11 @@ impl AsRawFd for Notifier {

/// A notify handle to the inner driver.
pub struct NotifyHandle {
fd: OwnedFd,
fd: Arc<OwnedFd>,
}

impl NotifyHandle {
pub(crate) fn new(fd: OwnedFd) -> Self {
pub(crate) fn new(fd: Arc<OwnedFd>) -> Self {
Self { fd }
}

Expand Down
12 changes: 6 additions & 6 deletions compio-driver/src/poll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn entry_cancelled(user_data: usize) -> Entry {

struct Notifier {
notify_reader: os_pipe::PipeReader,
notify_writer: os_pipe::PipeWriter,
notify_writer: Arc<os_pipe::PipeWriter>,
}

impl Notifier {
Expand All @@ -343,12 +343,12 @@ impl Notifier {

Ok(Self {
notify_reader,
notify_writer,
notify_writer: Arc::new(notify_writer),
})
}

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

pub fn clear(&self) -> io::Result<()> {
Expand All @@ -367,16 +367,16 @@ impl Notifier {

/// A notify handle to the inner driver.
pub struct NotifyHandle {
sender: os_pipe::PipeWriter,
sender: Arc<os_pipe::PipeWriter>,
}

impl NotifyHandle {
fn new(sender: os_pipe::PipeWriter) -> Self {
fn new(sender: Arc<os_pipe::PipeWriter>) -> Self {
Self { sender }
}

/// Notify the inner driver.
pub fn notify(&self) -> io::Result<()> {
(&self.sender).write_all(&[1u8])
(&*self.sender).write_all(&[1u8])
}
}
2 changes: 1 addition & 1 deletion compio-net/src/cmsg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cfg_if::cfg_if! {
/// Reference to a control message.
pub struct CMsgRef<'a>(sys::CMsgRef<'a>);

impl<'a> CMsgRef<'a> {
impl CMsgRef<'_> {
/// Returns the level of the control message.
pub fn level(&self) -> i32 {
self.0.level()
Expand Down
4 changes: 2 additions & 2 deletions compio-net/src/cmsg/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libc::{CMSG_DATA, CMSG_FIRSTHDR, CMSG_LEN, CMSG_NXTHDR, CMSG_SPACE, c_int, c

pub(crate) struct CMsgRef<'a>(&'a cmsghdr);

impl<'a> CMsgRef<'a> {
impl CMsgRef<'_> {
pub(crate) fn level(&self) -> c_int {
self.0.cmsg_level
}
Expand All @@ -23,7 +23,7 @@ impl<'a> CMsgRef<'a> {

pub(crate) struct CMsgMut<'a>(&'a mut cmsghdr);

impl<'a> CMsgMut<'a> {
impl CMsgMut<'_> {
pub(crate) fn set_level(&mut self, level: c_int) {
self.0.cmsg_level = level;
}
Expand Down
4 changes: 2 additions & 2 deletions compio-net/src/cmsg/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const fn wsa_cmsg_len(length: usize) -> usize {

pub struct CMsgRef<'a>(&'a CMSGHDR);

impl<'a> CMsgRef<'a> {
impl CMsgRef<'_> {
pub fn level(&self) -> i32 {
self.0.cmsg_level
}
Expand All @@ -76,7 +76,7 @@ impl<'a> CMsgRef<'a> {

pub(crate) struct CMsgMut<'a>(&'a mut CMSGHDR);

impl<'a> CMsgMut<'a> {
impl CMsgMut<'_> {
pub(crate) fn set_level(&mut self, level: i32) {
self.0.cmsg_level = level;
}
Expand Down
4 changes: 1 addition & 3 deletions compio-tls/tests/connect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::sync::Arc;

use compio_io::{AsyncReadExt, AsyncWrite, AsyncWriteExt};
use compio_net::TcpStream;
use compio_tls::TlsConnector;
Expand Down Expand Up @@ -33,7 +31,7 @@ async fn rtls() {
store.add(cert).unwrap();
}

let connector = TlsConnector::from(Arc::new(
let connector = TlsConnector::from(std::sync::Arc::new(
rustls::ClientConfig::builder()
.with_root_certificates(store)
.with_no_client_auth(),
Expand Down

0 comments on commit 464552d

Please sign in to comment.