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

Override poll_write_vectored? #26

Closed
thomaseizinger opened this issue Oct 29, 2023 · 5 comments · Fixed by #45
Closed

Override poll_write_vectored? #26

thomaseizinger opened this issue Oct 29, 2023 · 5 comments · Fixed by #45

Comments

@thomaseizinger
Copy link

At present, poll_write_vectored is not overridden:

I think it would make sense to do so though. At the moment, the implementation of poll_write will perform IO as soon as the buffer is written (which makes sense). However, if the application would have more data to send that sits in different buffers, performing IO after every poll_write might lead to multiple TCP packets being sent.

The only way around this (I think?) would be to re-design the upper layer to be able to provide a single byte buffer. That is not always feasible and/or desirable. Additionally, that is exactly what poll_write_vectored is for. A proper implementation of would send all packets down to the rustls session and only perform IO once that buffer is either full or we've written all buffers passed to us.

I've created a basic draft in #25.

@quininer
Copy link
Member

I agree with impl write_vectored as the optimization over current situation.

Currently, rustls does not provide backpressure https://github.com/rustls/rustls/blob/v/0.21.8/rustls/src/conn.rs#L232 . If we want to impl buffer write without rustls support, we can treat rustls writer as an infinite buffer and set a reasonable buffer length ourselves.

But this is a huge behavior change. and if rustls hopes to provide a write-through API in future, it would be reasonable to keep current behavior. tokio-rs/tls#136 (comment)

cc @djc

@thomaseizinger
Copy link
Author

I don't think I am following you there. Isn't that orthogonal to vectored writes? For poll_write_vectored to make sense, I think we simply need to first write all buffers and then ask the session wants_write.

The docs for poll_write_vectored state that it needs to behave as if poll_write was called with a concatenated buffer. How is internal buffering in rustls related to that?

@quininer
Copy link
Member

Yes, they are orthogonal. the buffer writer is just a related discussion of this line.

A proper implementation of would send all packets down to the rustls session and only perform IO once that buffer is either full or we've written all buffers passed to us.

@djc
Copy link
Member

djc commented Oct 30, 2023

The write-through API is currently being worked on. rustls/rustls#1420

@paolobarbolini
Copy link
Contributor

With rustls/rustls#1640 this could make sense to have. I may find some time to look into 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 a pull request may close this issue.

4 participants