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

tokio-rustls: how to use buffering with TlsStream? #136

Open
david-monroe opened this issue Mar 20, 2023 · 4 comments
Open

tokio-rustls: how to use buffering with TlsStream? #136

david-monroe opened this issue Mar 20, 2023 · 4 comments

Comments

@david-monroe
Copy link

david-monroe commented Mar 20, 2023

I have seen that internally a large read buffer is used. Therefore I do not believe that it makes sense to ever use additional read buffering with TlsStream.

However, poll_write calls the underlying poll_write every time. Would it therefore make sense to use BufWriter<TlsStream<TcpStream>> or is this BufWriter unnecessary?

@david-monroe david-monroe changed the title How to use buffering with TlsStream? tokio-rustls: how to use buffering with TlsStream? Mar 20, 2023
@quininer
Copy link
Member

poll_write calls the underlying poll_write every time.

I don't think this is correct, it only calls poll_write when it satisfies wants_write.

@david-monroe
Copy link
Author

david-monroe commented Mar 21, 2023

My interpretation was that wants_write returns true always if there is something to write at all.

    pub fn wants_write(&self) -> bool {
        !self.sendable_tls.is_empty()
    }

@quininer
Copy link
Member

quininer commented Mar 21, 2023

You seem to be right. given that rustls has a flush method, this seems to be a reserved behavior for rustls.

There are two buffer in write direction, one is sendable_plaintext before send and one is sendable_tls after send.
The sendable_plaintext is equivalent to BufWriter<TlsStream<TcpStream>>, and sendable_tls is equivalent to TlsStream<BufWriter<TcpStream>>.

Does rustls have any plan to expose write buffer? @ctz @djc

@djc
Copy link
Contributor

djc commented May 23, 2023

We have a plan to have an unbuffered/write-through API, where rustls doesn't maintain any buffers for the data path. I've made some progress on this over the past year, but the next step is non-trivial to implement.

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

No branches or pull requests

3 participants