Skip to content

Conversation

@teskje
Copy link
Contributor

@teskje teskje commented Oct 24, 2025

This PR adds the missing TcpStream::{into_}split and UnixStream::{into_}split APIs, as a step towards tokio parity.

UnixStream is currently just a mock type, so the new read/write half types are as well.

TcpStream has full support. Unfortunately, to support the borrowed ReadHalf/WriteHalf types, I had to make TcpStream interior-mutable by wrapping some of its fields into Mutexs. The resulting need for locking is a bit annoying. Lmk if anyone has a better idea!

@teskje teskje marked this pull request as ready for review October 24, 2025 17:01
@teskje teskje force-pushed the tokio-stream-split branch from 46c9905 to 8e4fcce Compare October 24, 2025 17:02
@BugenZhao
Copy link
Contributor

Unfortunately, to support the borrowed ReadHalf/WriteHalf types, I had to make TcpStream interior-mutable by wrapping some of its fields into Mutexs. The resulting need for locking is a bit annoying.

Using a spin lock here looks acceptable to me, as there appears to be no contention and it's just used for working around the borrow checker.

However, I'm still wondering if it's inevitable. Ideally the reader and the sender operates on different field of the TcpStream, thus it's feasible to split the mutable reference into a pair. Would you share more information on the difficulty you've encountered when attempting to implement it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants