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

Add a to_std method for tokio's TcpStream #3031

Closed
Daksh14 opened this issue Oct 23, 2020 · 8 comments · Fixed by #3189
Closed

Add a to_std method for tokio's TcpStream #3031

Daksh14 opened this issue Oct 23, 2020 · 8 comments · Fixed by #3189
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. C-proposal Category: a proposal and request for comments M-net Module: tokio/net

Comments

@Daksh14
Copy link
Contributor

Daksh14 commented Oct 23, 2020

Is your feature request related to a problem? Please describe.
Cannot convert from a tokio TcpStream to a std one which allows the conversion to a socket2 socket which allows editing various params for a TcpStream

Describe the solution you'd like
Implement a to_std method for tokio's TcpStream.

Describe alternatives you've considered
None considered

Additional context
None provided

@Daksh14 Daksh14 added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Oct 23, 2020
@Darksonn Darksonn added the M-net Module: tokio/net label Oct 23, 2020
@carllerche carllerche added E-help-wanted Call for participation: Help is requested to fix this issue. C-proposal Category: a proposal and request for comments labels Nov 12, 2020
@carllerche
Copy link
Member

It should be possible to impl TryFrom to convert between the two. We also could probably provide as_std(&self) -> &TcpStream.

I would be interested to hear what others think. cc @tokio-rs/maintainers

@Darksonn
Copy link
Contributor

Is the conversion fallible?

@carllerche
Copy link
Member

Converting will require deregistering, which could fail.

@Darksonn
Copy link
Contributor

I do think that a conversion is valuable. The as_std you proposed would also be neat.

@mariusmuja
Copy link

The absence of a way to convert from tokio TcpStream to std TcpStream is preventing me from updating from tokio 0.2 to 0.3.

In my use case, I have a custom TcpStream that also reads RX timestamps from the socket in addition to the payload. I can use AsyncFd, however I need to convert from a tokio::net::TcpStream (received from a tokio::net::TcpListener) to AsyncFd<std::net::TcpStream> and as far as I can tell there is no way of extracting the std::net::TcpStream and de-registering. I could write a custom TcpListener I guess, but I would be great if tokio's TcpStream had an into_std(self) or a TryFrom was available.

@liufuyang
Copy link
Contributor

Maybe I can help on this? Even though I don't have much TcpStream knowledge yet but I'd love to help and learn :)

@carlosb1
Copy link
Contributor

I was checking and I want to be sure... I see that the tcpStream is mapped in the mio library... should it extract the object from there and expose?

@Darksonn
Copy link
Contributor

Yeah, it should take out the mio TcpStream then convert it (possibly through IntoRawFd if necessary).

liufuyang added a commit to liufuyang/tokio that referenced this issue Nov 28, 2020
Fixes: tokio-rs#3031

Signed-off-by: Fuyang Liu <liufuyang@users.noreply.github.com>
liufuyang added a commit to liufuyang/tokio that referenced this issue Nov 28, 2020
Fixes: tokio-rs#3031

Signed-off-by: Fuyang Liu <liufuyang@users.noreply.github.com>
liufuyang added a commit to liufuyang/tokio that referenced this issue Nov 28, 2020
Fixes: tokio-rs#3031

Signed-off-by: Fuyang Liu <liufuyang@users.noreply.github.com>
@Darksonn Darksonn removed the E-help-wanted Call for participation: Help is requested to fix this issue. label Dec 10, 2020
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. C-proposal Category: a proposal and request for comments M-net Module: tokio/net
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants