Re: [EXTERNAL] - Details on using xcb_send_request()?
Junk Mail <ireallyhatespam-zJpx2rpV7r/[email protected]> Thu, 04 Feb 2021 15:50:02 +0000
| Newsgroups | gmane.comp.freedesktop.xcb |
|---|---|
| Message-ID | <[email protected]> |
- all I am going to assume that the part where you say "every X11 request must be a multiple of 4 bytes" is specific to the implementation, the protocol says: >Every request consists of four bytes of a header (containing the major opcode, the length field, and a data byte) followed by zero or more additional bytes of data. So every request is four bytes for header + data, if it has to be multiple of 4, then the text in the protocol should be updated to reflect this. 04.02.2021, 15:10, "Peter Harris" <[email protected]>: On 2021-02-03 Junk Mail wrote: xcb_parts[3].iov_base = 0; xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3; // why? Why? Padding / alignment. The next thing on the wire must be aligned to its natural size (a multiple of 4 bytes in this case). xcb_parts[4].iov_base = (char *) value_list; xcb_parts[4].iov_len = xcb_popcount(value_mask) * sizeof(uint32_t); xcb_parts[5].iov_base = 0; xcb_parts[5].iov_len = -xcb_parts[4].iov_len & 3; // why? Why? Padding / alignment. Every X11 request must be a multiple of 4 bytes. In this particular case, we can see that it is already aligned, so this will always have an iov_len of 0 (and thus nothing will be sent to the server for this part). The xcb generator is conservative and always emits this at the end of every request. It seems like there are "delimiters" (index 3 and 5 of xcb_parts, which is of type struct iovec), and their lengths are always the negative value of the length of the previous index AND'd with 3, I have found nothing obvious that could shed light It's a fast way to calculate the number of bytes of padding needed to "round up" to the required alignment. See, for example, https://stackoverflow.com/questions/20844983/what-is-the-best-way-to-calculate-number-of-padding-bytes for other ways to calculate this value. Peter Harris _______________________________________________ Xcb mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/xcb