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

Use &mut [IoSlice] for request sending #427

Open
psychon opened this issue May 22, 2020 · 3 comments
Open

Use &mut [IoSlice] for request sending #427

psychon opened this issue May 22, 2020 · 3 comments
Labels
help wanted Extra attention is needed P3 Priority Middle stable API Things that might require API changes

Comments

@psychon
Copy link
Owner

psychon commented May 22, 2020

XCBConnection creates a copy of the passed in slice of request buffers. So far, RustConnection does not, but instead switches between write_vectored and plain write for a buffer:

let remaining = &bufs[0][count..];
write.write_all(remaining, fds)?;

I think it should be possible to get rid of that write part by using a mutable slice for request sending. That way, partial writes can be done by replacing the respective IoSlice.

@psychon psychon added stable API Things that might require API changes P3 Priority Middle help wanted Extra attention is needed labels May 22, 2020
@psychon
Copy link
Owner Author

psychon commented May 23, 2020

Changing the public API from &[] to &mut [] is easy. Using this change in RustConnection::write_all_vectored then runs into lifetime problems. Oh and compute_length_field also ended up with lifetime problems. Someone who understands covariance and invariance may give this a shot.

Part of the problem is that I do not see how to implement https://doc.rust-lang.org/std/io/struct.IoSlice.html#method.advance on stable without unsafe code. When you have a &'b IoSlice<'a>, you can only get an &'b [u8], but would need an &'a [u8] to implement advance().

@notgull
Copy link
Collaborator

notgull commented Aug 11, 2022

I created the advance crate as an "unsafe-quarantine microcrate" to allow for usage of the advance function in stable environments. Using that, we could probably resolve this issue.

@eduardosm
Copy link
Collaborator

IoSlice::advance will be stabilized in Rust 1.81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed P3 Priority Middle stable API Things that might require API changes
Projects
None yet
Development

No branches or pull requests

3 participants