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

udp: Add split/into_split for UdpSocket #3358

Closed
wants to merge 4 commits into from

Conversation

leshow
Copy link
Contributor

@leshow leshow commented Dec 28, 2020

Motivation

With #2779 we don't need the split API anymore, however it still exists for UnixStream and TcpStream. Why not also for UdpSocket? It uses regular references or an Arc in the same way that the other types do.

Solution

Write a simple wrapper over regular references for shared split or Arc for owned split. @Darksonn seemed to be on board for this, thoughts?

@leshow
Copy link
Contributor Author

leshow commented Dec 28, 2020

This code currently fails on the visibility of RecvHalf/SendHalf. Where should these types be exported?

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-net Module: tokio/net labels Dec 28, 2020
@Darksonn
Copy link
Contributor

They should be exported in a new module tokio::net::udp.

@Darksonn
Copy link
Contributor

There appears to be a merge conflict.

@leshow
Copy link
Contributor Author

leshow commented Jan 19, 2021

I gave it a rebase off the latest master, didn't see any conflicts but it should now have the latest changes.

@carllerche
Copy link
Member

Split exists for TcpStream in order to get access to the AsyncRead / AsyncWrite trait implementations. UdpSocket does not have this requirement. When would one split a UdpSocket? I would rather avoid code if we can.

@leshow
Copy link
Contributor Author

leshow commented Jan 19, 2021

It's not necessary, but UnixStream doesn't implement AsyncRead/AsyncWrite and it can also be split. The PR came out of a discussion with @Darksonn on discord a little while ago, I think the desire was to have a similar interface for all the net types. If it's not wanted feel free to close.

@carllerche
Copy link
Member

UnixStream does implement the traits, e.g. https://docs.rs/tokio/1.0.2/tokio/net/unix/struct.ReadHalf.html#impl-AsyncRead

@leshow
Copy link
Contributor Author

leshow commented Jan 20, 2021

My mistake, I should have double checked before commenting.

@Darksonn
Copy link
Contributor

Closing in favor of #3448.

@Darksonn Darksonn closed this Jan 20, 2021
@ta3pks
Copy link

ta3pks commented May 6, 2021

I dont know why this is closed. There is no way to split a udp socket so how one writes something using udp sockets? @carllerche what makes you think udp sockets must be unsplittable ? one very simple usage is to pass two ends to two different tasks so simultaneous read/writes are possible

@Darksonn
Copy link
Contributor

Darksonn commented May 6, 2021

This was closed because you can already use an Arc to achieve the same purpose. See here for more.

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-net Module: tokio/net
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants