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 an Either type for Listeners #4048

Closed
qrnch-jan opened this issue Aug 20, 2021 · 7 comments
Closed

Add an Either type for Listeners #4048

qrnch-jan opened this issue Aug 20, 2021 · 7 comments
Labels
A-tokio-util Area: The tokio-util crate C-feature-request Category: A feature request. M-net Module: tokio/net

Comments

@qrnch-jan
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I want to be able to (easily) listen on either a UnixListener or TcpListener in the same function. Or, more precisely, I would like the freedom to nest other types as well, just as can be done with tokio-util's Either.

On the client side we have a function which parses the socket address string and detects if it's a local domain socket or not, and paired with a custom connection function we can easily allow the user to control whether to use local domain sockets or TCP simply by altering a configuration string. We want to be provide the same simplicity on the server end for the binding/listening.

Describe the solution you'd like
It would be nice to have an EitherListener (or equivalent) which works exactly like tokio-utik's Either, except that it works on the server end (i.e. .bind() and .accept()).

Describe alternatives you've considered
We have a hardwired solution, but the nice thing about Either is that it generic and supports nested types.

@qrnch-jan qrnch-jan added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Aug 20, 2021
@Darksonn Darksonn added A-tokio-util Area: The tokio-util crate M-net Module: tokio/net and removed A-tokio Area: The main tokio crate labels Aug 21, 2021
@Darksonn
Copy link
Contributor

Adding this to tokio-util is fine with me.

@Darksonn Darksonn added E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue. labels Sep 19, 2021
@hi-rustin
Copy link
Contributor

I am working on this.

@hi-rustin
Copy link
Contributor

@Darksonn When you have time, could you help describe what you think the right API looks like?

@Darksonn
Copy link
Contributor

Well there are probably several options. You could have an enum with the listener types hard-coded. You could also define a listener trait, which would have a poll_accept method, and have the enum's accept method work via that. If you use the trait, you could add the feature to the existing Either enum instead of adding a new one.

@Hodkinson
Copy link
Contributor

Hi @hi-rustin how's it going with this one? I could have a look at it this week if you like.

@Darksonn
Copy link
Contributor

Please note that this PR was recently posted: #4385

@Darksonn Darksonn removed E-help-wanted Call for participation: Help is requested to fix this issue. E-easy Call for participation: Experience needed to fix: Easy / not much labels Jan 27, 2022
@Darksonn
Copy link
Contributor

Fixed in #4385.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-util Area: The tokio-util crate C-feature-request Category: A feature request. M-net Module: tokio/net
Projects
None yet
Development

No branches or pull requests

4 participants