tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
26.59k stars 2.45k forks source link

Add `SimplexStream` structure #6589

Closed wutchzone closed 1 month ago

wutchzone commented 4 months ago

I think that it is unfortunate that the underlying structure backing the DuplexStream is not exposed. There are cases where a single direction will suffice, for example, when I have only a single writer and single reader, thus not requiring bidirectionality.

In this patch, I renamed the Pipe to the SimplexStream for coherence with the already existing DuplexStream and made it public

Darksonn commented 4 months ago

Adding a stream with one direction of communication seems reasonable, but I don't love the name SimplexStream. Maybe it's the best option, but can we come up with anything else? I guess there's the option of just keeping Pipe ...

wutchzone commented 4 months ago

My reasoning for not using Pipe is that it is already an overloaded term used for OS primitive, and someone could get confused by reusing it again. And since we have the DuplexStream I think™ that a better name is SimplexStream because these two structures are somewhat related.

But if you think it is negligible I will change it back to the Pipe.

robgjansen commented 2 months ago

A SimplexStream would be very useful and something I'm missing! You can split a TcpStream into read and write halves, so for testing I'd like to replace those with SimplexStreams. I also wonder if we might want to be able to split or into_split a DuplexStream into two SimplexStreamss?

Darksonn commented 2 months ago

Sorry, this PR has gotten lost. I'm happy to take it up again if you're still interested.

wutchzone commented 2 months ago

I would be glad to continue working on this feature (and possibly extending it into other structures, as @ robgjansen mentioned) . However, I am still uncertain whether we agree to name it SimplexStream or keep the original Pipe.

Darksonn commented 2 months ago

We can go with SimplexStream. Sorry for not replying earlier.

wutchzone commented 2 months ago

I am not sure whether it makes sense to add more tests to test the SimplexStream because DuplexStream (which already uses SimplexStream) has an extensive test suite.

Darksonn commented 1 month ago

Thanks!