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

UdpSocket.recv() using uninitialized Vec #5563

Closed
newfla opened this issue Mar 20, 2023 · 3 comments · Fixed by #5583
Closed

UdpSocket.recv() using uninitialized Vec #5563

newfla opened this issue Mar 20, 2023 · 3 comments · Fixed by #5583
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-net Module: tokio/net

Comments

@newfla
Copy link
Contributor

newfla commented Mar 20, 2023

Is your feature request related to a problem? Please describe.
As today UdpSocket.recv() and UdpSocket.recv_from() require a Vec<u8> with length > 0.
This prevents users to use a Vec<u8> created with Vec::with_capacity() for skipping the vec initialization; the methods always returns OK(0).

As workaround try_recv_buf_from and try_recv_buf are available but they increase the code complexity.

Describe the solution you'd like
I've considered the following alternatives:

  1. Implements recv_buf and recv_buf_from: they will work with buf having length=0 without the complication of try variants.

Describe alternatives you've considered

  1. Switching recv() and recv_from from &mut [u8] to &mut BufMut. I'm not sure if that's an acceptable solution

Additional context
As bonus point, it would be nice to improve methods documentations to underline the different behavior of the current methods: as today, the difference is only shown in the code snippets (not in the description).

@newfla newfla added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Mar 20, 2023
@Darksonn Darksonn added the M-net Module: tokio/net label Mar 20, 2023
@Darksonn
Copy link
Contributor

I don't mind adding recv_buf and recv_buf_from.

Changing the definition of recv is definitely not an acceptable solution. That would be a breaking change.

@newfla
Copy link
Contributor Author

newfla commented Mar 25, 2023

I noticed that it is possible to add the same methods also to the UnixDatagram struct.
@Darksonn, If you don't see any problems, I'll prepare a pull request in the next few days

@Darksonn
Copy link
Contributor

Thanks! Yes, they should be added to UnixDatagram too.

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 C-feature-request Category: A feature request. M-net Module: tokio/net
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants