Skip to content

Commit f14d3ef

Browse files
committed
fix(runtime): docs of Attacher and remove Attachable
1 parent 6b32de3 commit f14d3ef

File tree

8 files changed

+10
-55
lines changed

8 files changed

+10
-55
lines changed

compio-fs/src/file.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use compio_driver::{
77
syscall, AsRawFd,
88
};
99
use compio_io::{AsyncReadAt, AsyncWriteAt};
10-
use compio_runtime::{impl_attachable, impl_try_clone, Attacher, Runtime};
10+
use compio_runtime::{impl_try_clone, Attacher, Runtime};
1111
#[cfg(unix)]
1212
use {
1313
compio_buf::{IoVectoredBuf, IoVectoredBufMut},
@@ -217,6 +217,4 @@ impl AsyncWriteAt for &File {
217217

218218
impl_raw_fd!(File, inner);
219219

220-
impl_attachable!(File, inner);
221-
222220
impl_try_clone!(File, inner);

compio-fs/src/named_pipe.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{ffi::OsStr, io, ptr::null};
99
use compio_buf::{BufResult, IoBuf, IoBufMut};
1010
use compio_driver::{impl_raw_fd, op::ConnectNamedPipe, syscall, AsRawFd, FromRawFd, RawFd};
1111
use compio_io::{AsyncRead, AsyncReadAt, AsyncWrite, AsyncWriteAt};
12-
use compio_runtime::{impl_attachable, impl_try_clone, Runtime};
12+
use compio_runtime::{impl_try_clone, Runtime};
1313
use widestring::U16CString;
1414
use windows_sys::Win32::{
1515
Security::SECURITY_ATTRIBUTES,
@@ -232,8 +232,6 @@ impl AsyncWrite for &NamedPipeServer {
232232

233233
impl_raw_fd!(NamedPipeServer, handle);
234234

235-
impl_attachable!(NamedPipeServer, handle);
236-
237235
impl_try_clone!(NamedPipeServer, handle);
238236

239237
/// A [Windows named pipe] client.
@@ -357,8 +355,6 @@ impl AsyncWrite for &NamedPipeClient {
357355

358356
impl_raw_fd!(NamedPipeClient, handle);
359357

360-
impl_attachable!(NamedPipeClient, handle);
361-
362358
impl_try_clone!(NamedPipeClient, handle);
363359

364360
/// A builder structure for construct a named pipe with named pipe-specific

compio-fs/src/pipe.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use compio_driver::{
99
syscall, AsRawFd, FromRawFd, IntoRawFd,
1010
};
1111
use compio_io::{AsyncRead, AsyncWrite};
12-
use compio_runtime::{impl_attachable, impl_try_clone, Runtime};
12+
use compio_runtime::{impl_try_clone, Runtime};
1313

1414
use crate::File;
1515

@@ -383,8 +383,6 @@ impl AsyncWrite for &Sender {
383383

384384
impl_raw_fd!(Sender, file);
385385

386-
impl_attachable!(Sender, file);
387-
388386
impl_try_clone!(Sender, file);
389387

390388
/// Reading end of a Unix pipe.
@@ -508,8 +506,6 @@ impl AsyncRead for &Receiver {
508506

509507
impl_raw_fd!(Receiver, file);
510508

511-
impl_attachable!(Receiver, file);
512-
513509
impl_try_clone!(Receiver, file);
514510

515511
/// Checks if file is a FIFO

compio-net/src/socket.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use compio_driver::{
99
},
1010
AsRawFd,
1111
};
12-
use compio_runtime::{impl_attachable, impl_try_clone, Attacher, Runtime};
12+
use compio_runtime::{impl_try_clone, Attacher, Runtime};
1313
use socket2::{Domain, Protocol, SockAddr, Socket as Socket2, Type};
1414

1515
#[derive(Debug)]
@@ -206,6 +206,4 @@ impl Socket {
206206

207207
impl_raw_fd!(Socket, socket);
208208

209-
impl_attachable!(Socket, socket);
210-
211209
impl_try_clone!(Socket, socket);

compio-net/src/tcp.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{future::Future, io, net::SocketAddr};
33
use compio_buf::{BufResult, IoBuf, IoBufMut, IoVectoredBuf, IoVectoredBufMut};
44
use compio_driver::impl_raw_fd;
55
use compio_io::{AsyncRead, AsyncWrite};
6-
use compio_runtime::{impl_attachable, impl_try_clone};
6+
use compio_runtime::impl_try_clone;
77
use socket2::{Protocol, SockAddr, Type};
88

99
use crate::{OwnedReadHalf, OwnedWriteHalf, ReadHalf, Socket, ToSocketAddrsAsync, WriteHalf};
@@ -111,8 +111,6 @@ impl TcpListener {
111111

112112
impl_raw_fd!(TcpListener, inner);
113113

114-
impl_attachable!(TcpListener, inner);
115-
116114
impl_try_clone!(TcpListener, inner);
117115

118116
/// A TCP stream between a local and a remote socket.
@@ -279,6 +277,4 @@ impl AsyncWrite for &TcpStream {
279277

280278
impl_raw_fd!(TcpStream, inner);
281279

282-
impl_attachable!(TcpStream, inner);
283-
284280
impl_try_clone!(TcpStream, inner);

compio-net/src/udp.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{future::Future, io, net::SocketAddr};
22

33
use compio_buf::{BufResult, IoBuf, IoBufMut, IoVectoredBuf, IoVectoredBufMut};
44
use compio_driver::impl_raw_fd;
5-
use compio_runtime::{impl_attachable, impl_try_clone};
5+
use compio_runtime::impl_try_clone;
66
use socket2::{Protocol, SockAddr, Type};
77

88
use crate::{Socket, ToSocketAddrsAsync};
@@ -253,6 +253,4 @@ impl UdpSocket {
253253

254254
impl_raw_fd!(UdpSocket, inner);
255255

256-
impl_attachable!(UdpSocket, inner);
257-
258256
impl_try_clone!(UdpSocket, inner);

compio-net/src/unix.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{future::Future, io, path::Path};
33
use compio_buf::{BufResult, IoBuf, IoBufMut, IoVectoredBuf, IoVectoredBufMut};
44
use compio_driver::impl_raw_fd;
55
use compio_io::{AsyncRead, AsyncWrite};
6-
use compio_runtime::{impl_attachable, impl_try_clone};
6+
use compio_runtime::impl_try_clone;
77
use socket2::{SockAddr, Type};
88

99
use crate::{OwnedReadHalf, OwnedWriteHalf, ReadHalf, Socket, WriteHalf};
@@ -90,8 +90,6 @@ impl UnixListener {
9090

9191
impl_raw_fd!(UnixListener, inner);
9292

93-
impl_attachable!(UnixListener, inner);
94-
9593
impl_try_clone!(UnixListener, inner);
9694

9795
/// A Unix stream between two local sockets on Windows & WSL.
@@ -264,8 +262,6 @@ impl AsyncWrite for &UnixStream {
264262

265263
impl_raw_fd!(UnixStream, inner);
266264

267-
impl_attachable!(UnixStream, inner);
268-
269265
#[cfg(windows)]
270266
#[inline]
271267
fn empty_unix_socket() -> SockAddr {

compio-runtime/src/attacher.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub struct Attacher<S> {
3030
}
3131

3232
impl<S: AsRawFd> Attacher<S> {
33-
/// Create [`Attacher`].
33+
/// Create [`Attacher`]. It tries to attach the source, and will return
34+
/// [`Err`] if it fails.
3435
pub fn new(source: S) -> io::Result<Self> {
3536
let this = Self {
3637
source,
@@ -41,7 +42,7 @@ impl<S: AsRawFd> Attacher<S> {
4142
}
4243

4344
/// Attach the source. This method could be called many times, but if the
44-
/// action fails, the error will only return once.
45+
/// action fails, it will try to attach the source during each call.
4546
fn attach(&self) -> io::Result<()> {
4647
let r = Runtime::current();
4748
let inner = r.inner();
@@ -51,12 +52,6 @@ impl<S: AsRawFd> Attacher<S> {
5152
}
5253
}
5354

54-
impl<S> Attachable for Attacher<S> {
55-
fn is_attached(&self) -> bool {
56-
self.once.get().is_some()
57-
}
58-
}
59-
6055
impl<S: IntoRawFd> IntoRawFd for Attacher<S> {
6156
fn into_raw_fd(self) -> RawFd {
6257
self.source.into_raw_fd()
@@ -106,12 +101,6 @@ impl<S> DerefMut for Attacher<S> {
106101
}
107102
}
108103

109-
/// Represents an attachable resource to driver.
110-
pub trait Attachable {
111-
/// Check if [`Attachable::attach`] has been called.
112-
fn is_attached(&self) -> bool;
113-
}
114-
115104
/// Duplicatable file or socket.
116105
pub trait TryClone: Sized {
117106
/// Duplicate the source.
@@ -151,18 +140,6 @@ impl TryClone for OwnedFd {
151140
}
152141
}
153142

154-
#[macro_export]
155-
#[doc(hidden)]
156-
macro_rules! impl_attachable {
157-
($t:ty, $inner:ident) => {
158-
impl $crate::Attachable for $t {
159-
fn is_attached(&self) -> bool {
160-
self.$inner.is_attached()
161-
}
162-
}
163-
};
164-
}
165-
166143
#[macro_export]
167144
#[doc(hidden)]
168145
macro_rules! impl_try_clone {

0 commit comments

Comments
 (0)