Skip to content
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

Set IOSQE_ASYNC for some operations #123

Merged
merged 4 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Asynchronous filesystem manipulation operations.
//! Filesystem manipulation operations.
//!
//! To open a file ([`AsyncFd`]) use [`open_file`] or [`OpenOptions`].

Expand Down
2 changes: 1 addition & 1 deletion src/mem.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Asynchronous memory operations.
//! Memory operations.

use std::future::Future;
use std::io;
Expand Down
4 changes: 3 additions & 1 deletion src/net.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Asynchronous networking.
//! Networking.
//!
//! To create a new socket ([`AsyncFd`]) use the [`socket`] function, which
//! issues a non-blocking `socket(2)` call.
Expand Down Expand Up @@ -1027,6 +1027,7 @@ op_future! {
let (ptr, len) = SocketAddress::as_mut_ptr(&mut address.0);
address.1 = len;
submission.accept(fd.fd(), ptr, &mut address.1, flags);
submission.set_async();
D::create_flags(submission);
},
map_result: |this, (address,), fd| {
Expand All @@ -1049,6 +1050,7 @@ op_async_iter! {
setup_state: flags: libc::c_int,
setup: |submission, this, flags| unsafe {
submission.multishot_accept(this.fd.fd(), flags);
submission.set_async();
D::create_flags(submission);
},
map_result: |this, _flags, fd| {
Expand Down
6 changes: 6 additions & 0 deletions src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ impl Submission {
self.inner.flags |= libc::IOSQE_CQE_SKIP_SUCCESS;
}

/// Don't attempt to do the operation non-blocking first, always execute it
/// in an async manner.
pub(crate) fn set_async(&mut self) {
self.inner.flags |= libc::IOSQE_ASYNC;
}

/// Set the flag to use direct descriptors.
pub(crate) fn use_direct_fd(&mut self) {
self.inner.flags |= libc::IOSQE_FIXED_FILE;
Expand Down
2 changes: 2 additions & 0 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl<'sq> Future for OneshotPoll<'sq> {
ctx,
|submission, (fd, mask)| unsafe {
submission.poll(fd, mask as u32);
submission.set_async();
}
);

Expand Down Expand Up @@ -91,6 +92,7 @@ impl<'sq> Drop for OneshotPoll<'sq> {
if let OpState::Running(op_index) = self.state {
let result = self.sq.cancel_op(op_index, (), |submission| unsafe {
submission.remove_poll(op_index);
submission.set_async();
// We'll get a canceled completion event if we succeeded, which
// is sufficient to cleanup the operation.
submission.no_completion_event();
Expand Down
3 changes: 3 additions & 0 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ op_future! {
setup: |submission, fd, (info,), _unused| unsafe {
let ptr = (**info).as_mut_ptr().cast();
submission.read_at(fd.fd(), ptr, size_of::<libc::signalfd_siginfo>() as u32, NO_OFFSET);
submission.set_async();
D::use_flags(submission);
},
map_result: |this, (info,), n| {
#[allow(clippy::cast_sign_loss)] // Negative values are mapped to errors.
Expand Down Expand Up @@ -524,6 +526,7 @@ impl<D: Descriptor> ReceiveSignals<D> {
size_of::<libc::signalfd_siginfo>() as u32,
NO_OFFSET,
);
submission.set_async();
D::use_flags(submission);
});
match result {
Expand Down
8 changes: 3 additions & 5 deletions tests/async_fd/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,9 @@ fn cancel_all_twice_accept() {
let n = waker
.block_on(listener.cancel_all())
.expect("failed to cancel all calls");
assert_eq!(n, 1);
let n = waker
.block_on(listener.cancel_all())
.expect("failed to cancel all calls");
assert_eq!(n, 0);
// Because the the accept call is asynchronous we can cancel up to one
// operations.
assert!(n <= 1);

expect_io_errno(waker.block_on(accept), libc::ECANCELED);
}
Expand Down
Loading