-
Notifications
You must be signed in to change notification settings - Fork 0
7992: io: AioSource now employs IO Safety #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ca7d441
b19e713
e397fc4
5c1df99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,17 +9,36 @@ use mio::Token; | |
| use std::fmt; | ||
| use std::io; | ||
| use std::ops::{Deref, DerefMut}; | ||
| use std::os::unix::io::AsRawFd; | ||
| use std::os::unix::prelude::RawFd; | ||
| use std::os::fd::{AsFd, BorrowedFd}; | ||
| use std::os::unix::io::{AsRawFd, RawFd}; | ||
| use std::task::{ready, Context, Poll}; | ||
|
|
||
| /// Like [`mio::event::Source`], but for POSIX AIO only. | ||
| /// | ||
| /// Tokio's consumer must pass an implementor of this trait to create a | ||
| /// [`Aio`] object. | ||
| /// [`Aio`] object. Implementors must implement at least one of [`AioSource::register`] and | ||
| /// [`AioSource::register_borrowed`]. | ||
| pub trait AioSource { | ||
| /// Registers this AIO event source with Tokio's reactor. | ||
| fn register(&mut self, kq: RawFd, token: usize); | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// It's memory-safe safe, but not I/O safe. If the file referenced by `kq` gets dropped, then | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:good-to-have; category:documentation; feedback: The Augment AI reviewer is correct! memory-safe safe sounds wrong. One of the occurrences of safe should be removed. |
||
| /// this source may end up notifying the wrong file. | ||
| #[deprecated(since = "1.51.0", note = "use register_borrowed instead")] | ||
| fn register(&mut self, _kq: RawFd, _token: usize) { | ||
| // This default implementation exists so new AioSource implementors that implement the | ||
| // register_borrowed method can compile without the need to implement register. | ||
| unimplemented!("Use AioSource::register_borrowed instead") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:incorrect-but-reasonable; category:bug; feedback: The Augment AI reviewer is not correct! The important function now is |
||
| } | ||
|
|
||
| /// Registers this AIO event source with Tokio's reactor. | ||
| fn register_borrowed(&mut self, kq: BorrowedFd<'_>, token: usize) { | ||
| // This default implementation serves to provide backwards compatibility with AioSource | ||
| // implementors written before 1.51.0 that only implemented the unsafe `register` method. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: low 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:incorrect-but-reasonable; category:bug; feedback: The Augment AI reviewer is not correct! Here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: low 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. value:incorrect-but-reasonable; category:bug; feedback: The Augment AI reviewer is not correct! Here unsafe is confused with Rust's unsafe keyword while it actually means that the usage of RawFD is more unsafe than using BorrowedFS/OwnedFD. |
||
| #[allow(deprecated)] | ||
| self.register(kq.as_raw_fd(), token) | ||
| } | ||
|
|
||
| /// Deregisters this AIO event source with Tokio's reactor. | ||
| fn deregister(&mut self); | ||
|
|
@@ -37,7 +56,8 @@ impl<T: AioSource> Source for MioSource<T> { | |
| interests: mio::Interest, | ||
| ) -> io::Result<()> { | ||
| assert!(interests.is_aio() || interests.is_lio()); | ||
| self.0.register(registry.as_raw_fd(), usize::from(token)); | ||
| self.0 | ||
| .register_borrowed(registry.as_fd(), usize::from(token)); | ||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -53,7 +73,8 @@ impl<T: AioSource> Source for MioSource<T> { | |
| interests: mio::Interest, | ||
| ) -> io::Result<()> { | ||
| assert!(interests.is_aio() || interests.is_lio()); | ||
| self.0.register(registry.as_raw_fd(), usize::from(token)); | ||
| self.0 | ||
| .register_borrowed(registry.as_fd(), usize::from(token)); | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the documentation: "memory-safe safe" should be "memory-safe".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value:good-to-have; category:documentation; feedback: The Gemini AI reviewer is correct!
memory-safe safesounds wrong. One of the occurrences ofsafeshould be removed.