-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
io: add AsyncFd::try_io() and try_io_mut() #6967
Conversation
035771b
to
298f98b
Compare
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.
Overall looks good to me. Are you able to fix the merge conflict?
This allows to provide APIs like `try_recv()` and `try_send()` in custom types built on top of `AsyncFd`.
298f98b
to
608bba2
Compare
Rebased on current master, and switched the test to use |
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.
Thanks.
Bumps tokio from 1.41.1 to 1.42.0. Release notes Sourced from tokio's releases. Tokio v1.42.0 1.42.0 (Dec 3rd, 2024) Added io: add AsyncFd::{try_io, try_io_mut} (#6967) Fixed io: avoid ptr->ref->ptr roundtrip in RegistrationSet (#6929) runtime: do not defer yield_now inside block_in_place (#6999) Changes io: simplify io readiness logic (#6966) Documented net: fix docs for tokio::net::unix::{pid_t, gid_t, uid_t} (#6791) time: fix a typo in Instant docs (#6982) #6791: tokio-rs/tokio#6791 #6929: tokio-rs/tokio#6929 #6966: tokio-rs/tokio#6966 #6967: tokio-rs/tokio#6967 #6982: tokio-rs/tokio#6982 #6999: tokio-rs/tokio#6999 Commits bb9d570 chore: prepare Tokio v1.42.0 (#7005) af9c683 tests: fix typo in build test instructions (#7004) 4bc5a1a ci: allow Unicode-3.0 license for unicode-ident (#7006) f8948ea runtime: do not defer yield_now inside block_in_place (#6999) bce9780 time: use array::from_fn instead of manually creating array (#7000) 38151f3 readme: unlist 1.32.x as LTS release (#6997) 5dda72d ci: pin valgrind to rustc 1.82 (#6998) c07257f io: simplify io readiness logic (#6966) d08578f time: fix a typo in Instant docs (#6982) 4047d79 miri: add annotations for tests with miri ignore (#6981) Additional commits viewable in compare view Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase. Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: @dependabot rebase will rebase this PR @dependabot recreate will recreate this PR, overwriting any edits that have been made to it @dependabot merge will merge this PR after your CI passes on it @dependabot squash and merge will squash and merge this PR after your CI passes on it @dependabot cancel merge will cancel a previously requested merge and block automerging @dependabot reopen will reopen this PR if it is closed @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually @dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
This allows to provide APIs like
try_recv()
andtry_send()
in custom types built on top ofAsyncFd
.Closes #4719.
Motivation
Custom types built on top of
AsyncFd
may want to provide functions liketry_recv()
andtry_send()
. Currently, I don't think this can be done cleanly, because thepoll_[read|write]_ready()
functions will register the current task to be woken. They use the reserved waker slot, so they would interfere with other users ofpoll_{ready,write}_ready()
, such asAsyncRead
andAsyncWrite
implementations.I suppose you currently could poll the future from
{read,write}_ready()
once with a fake waker. But that is quite a hacky workaround, and if the future is not ready, the fake waker would actually be registered only to be removed again directly after the polling.Solution
Add
AsyncFd::try_io()
andAsyncFd::try_io_mut()
to mirror the API fromUnixDatagram
other sockets. There is a mut and non-mut version to allow mut or const access to the wrapped resource as required, just likeAsyncFd::async_io[_mut]()
.Example
To illustrate why this is useful, consider the current implementation of a
try_recv()
function:Or, if we have
try_io
:No unnecessary wakers being registered, no unsafe code to avoid Arcs in the waker.