Skip to content

Commit 9116999

Browse files
authored
io: recommend OwnedFd with AsyncFd (#6821)
Signed-off-by: Alice Ryhl <[email protected]>
1 parent 8046a87 commit 9116999

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

spellcheck.dic

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
285
1+
286
22
&
33
+
44
<
@@ -99,6 +99,7 @@ errored
9999
EWMA
100100
expirations
101101
fcntl
102+
fd
102103
fd's
103104
FIFOs
104105
filename

tokio/src/io/async_fd.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ use std::task::{ready, Context, Poll};
2121
/// the [`AsyncFd`] is dropped.
2222
///
2323
/// The [`AsyncFd`] takes ownership of an arbitrary object to represent the IO
24-
/// object. It is intended that this object will handle closing the file
24+
/// object. It is intended that the inner object will handle closing the file
2525
/// descriptor when it is dropped, avoiding resource leaks and ensuring that the
2626
/// [`AsyncFd`] can clean up the registration before closing the file descriptor.
2727
/// The [`AsyncFd::into_inner`] function can be used to extract the inner object
28-
/// to retake control from the tokio IO reactor.
28+
/// to retake control from the tokio IO reactor. The [`OwnedFd`] type is often
29+
/// used as the inner object, as it is the simplest type that closes the fd on
30+
/// drop.
2931
///
3032
/// The inner object is required to implement [`AsRawFd`]. This file descriptor
3133
/// must not change while [`AsyncFd`] owns the inner object, i.e. the
@@ -175,6 +177,7 @@ use std::task::{ready, Context, Poll};
175177
/// [`TcpStream::poll_read_ready`]: struct@crate::net::TcpStream
176178
/// [`AsyncRead`]: trait@crate::io::AsyncRead
177179
/// [`AsyncWrite`]: trait@crate::io::AsyncWrite
180+
/// [`OwnedFd`]: struct@std::os::fd::OwnedFd
178181
pub struct AsyncFd<T: AsRawFd> {
179182
registration: Registration,
180183
// The inner value is always present. the Option is required for `drop` and `into_inner`.

0 commit comments

Comments
 (0)