Function x11rb::connection::compute_length_field
source ยท pub fn compute_length_field<'b>(
conn: &impl RequestConnection,
request_buffers: &'b [IoSlice<'b>],
storage: &'b mut (Vec<IoSlice<'b>>, [u8; 8]),
) -> Result<&'b [IoSlice<'b>], ConnectionError>
Expand description
Check the request length and use BIG-REQUESTS if necessary.
Users of this library will most likely not want to use this function directly.
This function is used by implementations of RequestConnection
for sending requests. It
examines the given request buffers and checks that the length field is set correctly.
If the request has more than 2^18 bytes, this function handles using the BIG-REQUESTS
extension. The request is rewritten to include the correct length field. For this case, the
storage
parameter is needed. This function uses it to store the necessary buffers.
When using this function, it is recommended to allocate the storage
parameter with
Default::default()
.
Example usage:
use std::io::IoSlice;
use x11rb::connection::{BufWithFds, RequestConnection, compute_length_field};
use x11rb::cookie::{Cookie, CookieWithFds, VoidCookie};
use x11rb::errors::{ParseError, ConnectionError};
use x11rb::utils::RawFdContainer;
use x11rb::x11_utils::{ExtensionInformation, TryParse, TryParseFd};
use x11rb_protocol::SequenceNumber;
struct MyConnection();
impl RequestConnection for MyConnection {
type Buf = Vec<u8>;
// [snip, other functions here]
fn send_request_with_reply<R>(&self, bufs: &[IoSlice], fds: Vec<RawFdContainer>)
-> Result<Cookie<Self, R>, ConnectionError>
where R: TryParse {
Ok(Cookie::new(self, self.send_request(bufs, fds, true, false)?))
}
fn send_request_with_reply_with_fds<R>(&self, bufs: &[IoSlice], fds: Vec<RawFdContainer>)
-> Result<CookieWithFds<Self, R>, ConnectionError>
where R: TryParseFd {
Ok(CookieWithFds::new(self, self.send_request(bufs, fds, true, true)?))
}
fn send_request_without_reply(&self, bufs: &[IoSlice], fds: Vec<RawFdContainer>)
-> Result<VoidCookie<Self>, ConnectionError> {
Ok(VoidCookie::new(self, self.send_request(bufs, fds, false, false)?))
}
}
impl MyConnection {
fn send_request(&self, bufs: &[IoSlice], fds: Vec<RawFdContainer>,
has_reply: bool, reply_has_fds: bool)
-> Result<SequenceNumber, ConnectionError>
{
let mut storage = Default::default();
let bufs = compute_length_field(self, bufs, &mut storage)?;
unimplemented!("Now send bufs and fds to the X11 server");
}
}