tokio-rustls icon indicating copy to clipboard operation
tokio-rustls copied to clipboard

Split `TlsStream` like `TcpStream`

Open jmmaloney4 opened this issue 1 year ago • 4 comments

Tokio allows splitting a TcpStream into a (Owned)ReadHalf / (Owned)WriteHalf via TcpStream::split / TcpStream::into_split, but I don't believe tokio_rustls allows splitting a TlsStream that wraps a TcpStream. Is there a way to do this with the current API that I'm not thinking of? If not, I'd be interested in helping to implement this feature.

The split method in TcpStream above is not the same as tokio::io::split. It supports true simultaneous reads and writes as opposed to just locking around the syscalls.

jmmaloney4 avatar Sep 16 '24 15:09 jmmaloney4

I believe the Deno folks have worked on something in this space: https://github.com/denoland/rustls-tokio-stream that might be a useful comparison point.

There's some previous discussion in an issue that was created when the Rustls specific code lived alongside the native-tls code in https://github.com/tokio-rs/tls/issues/40

cpu avatar Sep 16 '24 17:09 cpu

@cpu tokio-rustls is not affected by https://github.com/tokio-rs/tls/issues/40 .

Any split stream based on rustls must be locked until rustls support full-duplex mode. https://github.com/rustls/rustls/issues/288

quininer avatar Sep 16 '24 23:09 quininer

@cpu tokio-rustls is not affected by https://github.com/tokio-rs/tls/issues/40 .

Ah! Thanks for clarifying. I had indeed missed that this discussion was centered around native-tls.

cpu avatar Sep 17 '24 16:09 cpu

rustls-tokio-stream

rustls-tokio-stream is not really "lockfree tlsstream split". because this crate uses tokio::io::split which is based on std Mutex, the readhalf and writehalf before using should be locked.

miaomiao1992 avatar Jan 30 '25 15:01 miaomiao1992