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

io: add copy_bidirectional_with_sizes #6500

Merged

Conversation

RRRadicalEdward
Copy link
Contributor

@RRRadicalEdward RRRadicalEdward commented Apr 20, 2024

Motivation

copy_bidirectional uses 8Kb buffers under the hood, which isn't configurable.

Solution

New method copy_bidirectional_with_sizes were added which but accepts the a -> b and b -> a buffers sizes. This way, a user can pass the desire buffers sizes.
I extracted common copy_bidirectional logic into copy_bidirectional_impl which copy_bidirectional and copy_bidirectional_with_sizes uses.

Fixes: #6454.
Refs: #3572.

This is the same as `copy_bidirectional` but accepts the `a` -> `b` and `b` -> `a` buffers sizes.
`copy_bidirectional` uses 8Kb buffers under the hood which isn't
configurable. `copy_bidirectional_with_size` fixes it by allowing an
user to set its own sizes for underlying buffers.

Fixes: tokio-rs#6454.
Refs: tokio-rs#3572.
@RRRadicalEdward RRRadicalEdward force-pushed the copy_bidirectional_with_size branch from 776f21b to 90315d2 Compare April 20, 2024 10:45
@Darksonn Darksonn added A-tokio Area: The main tokio crate M-io Module: tokio/io labels Apr 20, 2024
tokio/src/io/util/copy_bidirectional.rs Outdated Show resolved Hide resolved
tokio/src/io/util/copy_bidirectional.rs Outdated Show resolved Hide resolved
tokio/src/io/util/copy_bidirectional.rs Outdated Show resolved Hide resolved
@RRRadicalEdward RRRadicalEdward changed the title io: add copy_bidirectional_with_size io: add copy_bidirectional_with_sizes Apr 21, 2024
Copy link
Member

@mox692 mox692 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, it looks almost good.

tokio/src/io/util/copy_bidirectional.rs Outdated Show resolved Hide resolved
Co-authored-by: Motoyuki Kimura <[email protected]>
Copy link
Member

@mox692 mox692 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@Darksonn Darksonn merged commit 8093712 into tokio-rs:master Apr 22, 2024
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-io Module: tokio/io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No option to choose buffer capacity for copy_bidrectional
4 participants