Option::filter() exists since Rust 1.27.0, and is much more readable
than the open coded variant that was there before, using
Option::and_then().
This has been found by clippy.
This impl was missing to be able to create a tokio::fs::File directly
from an OwnedFd, which can be done in a safe way. Going through RawFd
required unsafe for the same operation.
And same for Windows using a OwnedHandle instead.
Since #5223, `yield_now` does not wake the task immediately. Instead,
the waker is handed to the scheduler via `context::defer`, which wakes
it only after running out of ready tasks and polling the IO/timer
driver. Add a comment explaining this, as the reasoning is not obvious
from the bare `context::defer` call.
I recently fixed a memory leak in an application where tokio's RawTask
storage was being kept alive by a leaked Waker. The task itself was
polling an `mpsc::Receiver` before then being aborted. During cleanup,
all references to the RawTask were dropped, except for the one stored in
`mpsc::chan::Chan::rx_waker`. While the `Receiver` was dropped as part
of the task's future, one of the channel's `Sender`s was leaked outside
the task. This meant the `Chan` was never dropped and its `rx_waker`
contained the leaked Waker.
I fixed the leak by properly cleaning up the `Sender`, but I also think
keeping `rx_waker` around in this case is unnecessary. Once `chan::Rx`
is dropped, it can't be polled anymore, so waking up the registered task
will always be spurious.
The commit includes a regression test to illustrate the problem that is
fixed by removing the waker explicitly.
Expand module and API docs around RecvError::Lagged / TryRecvError::Lagged
so capacity rounding, miss counts, and post-lag resume behavior are explicit.
Add integration tests covering slow receivers within capacity, overflow,
per-receiver lag, async recv, and cursor advancement after Lagged.
Add #[inline] hints to poll_read, poll_write, start_seek, poll_complete, poll_fill_buf, and consume implementations for in-memory types (&[u8], Vec<u8>, Cursor<T>).
These are small, leaf implementations that benefit from cross-crate inlining, enabling LLVM to optimize call sites in downstream crates (including bounds-check elision and dead-code path elimination).
Benchmarks show ~16% improvement for slice reads and ~20% for cursor writes.
Replace 'i dont' with 'i don't' in the cfg(not(unix)) stub of
'check_socket_for_blocking'. The line is a casual internal comment
about why WASI is not yet supported there; it just needs the missing
apostrophe.
The timeout doc said the timeout is checked before polling the future,
but the impl polls the future first and only then checks the delay (see
the Future impl for Timeout, which calls me.value.poll before
poll_delay). Reverse the clause to match the implementation. This is
also what makes the rest of the sentence correct: the future can
complete and exceed the timeout without an error precisely because it is
polled before the timeout is checked.
Co-authored-by: Patrick Wehbe <[email protected]>
* implement Op<Statx> and use it to implement fs::try_exists
* fix statx on unavailable platforms
* complete using only io-uring operations for read_uring
* Implemented io-uring::Op<Statx> and apply it accordingly to read_uring, try_exists
* Added test for io uring statx operations. Checks for cancellations, shutdown, stating multiple files, ELOOP, ENAMETOOLONG, EACCES
* Removed musl as supported platform for io_uring statx operations, as statx is supported on 1.25+ musl, and MSRV that uses 1.25 on all *-linux-musl platforms is 1.93
* Removed pending checks for cancel_op_future since io_uring not available on Linux <5.1, removed stat permission denied test case since it doesn't work on Linux 4.19
* Removed redundant cfg attributes on functions, added STATX_BTIME flag in statx operation, use assert pending in cancel ops
* Uncommented stat_permission_denied test and make sure it doesn't run on platforms that don't support io_uring, removed unnecessary comments, and added TODO on symlink_metadata for when Metadata::from_statx is stabilized
* Statx fd leak drop test added and added STATX_BTIME to file_metadata
* Remove unnecessary utils function, refactored code in statx and statx fd leak test, and removed cfg_io_uring gates (localized the feature gate to the pertinent part of the code that uses it in read_uring)
---------
Co-authored-by: Vrtgs <[email protected]>
The test asserts shutdown() returns Ok(()) after the peer resets the
connection (linger = 0). This holds on Linux and macOS, but on FreeBSD the
kernel can finish processing the RST before shutdown() runs, so it returns
ConnectionReset and the test fails intermittently -- the oneshot only
synchronizes the application-level drop, not the kernel's RST processing.
Accept Ok(()) or ConnectionReset for the post-reset shutdown, since both
are valid for a connection the peer has already reset.