<div>- all</div><div> </div><div>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:</div><div><span style="font-size:16px;line-height:24px">><span style="color:#000000;float:none;font-family:'bitstream vera sans' , 'dejavu sans' , 'tahoma' , 'geneva' , 'arial' , sans-serif;font-style:normal;font-weight:400;text-decoration-style:initial;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">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.</span></span></div><div><span style="font-size:16px;line-height:24px"><span style="color:#000000;float:none;font-family:'bitstream vera sans' , 'dejavu sans' , 'tahoma' , 'geneva' , 'arial' , sans-serif;font-style:normal;font-weight:400;text-decoration-style:initial;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">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.</span></span></div><div> </div><div>04.02.2021, 15:10, "Peter Harris" <pharris@opentext.com>:</div><blockquote><p>On 2021-02-03 Junk Mail wrote:</p><blockquote> xcb_parts[3].iov_base = 0;<br /> xcb_parts[3].iov_len = -xcb_parts[2].iov_len & 3; // why?</blockquote><p><br />Why? Padding / alignment. The next thing on the wire must be aligned to its natural size (a multiple of 4 bytes in this case).<br /> </p><blockquote> xcb_parts[4].iov_base = (char *) value_list; xcb_parts[4].iov_len =<br /> xcb_popcount(value_mask) * sizeof(uint32_t);<br /> <br /> xcb_parts[5].iov_base = 0;<br /> xcb_parts[5].iov_len = -xcb_parts[4].iov_len & 3; // why?</blockquote><p><br />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.<br /> </p><blockquote> It seems like there are "delimiters" (index 3 and 5 of xcb_parts,<br /> which is of type struct iovec), and their lengths are always the<br /> negative value of the length of the previous index AND'd with 3, I<br /> have found nothing obvious that could shed light</blockquote><p><br />It's a fast way to calculate the number of bytes of padding needed to "round up" to the required alignment.<br /><br />See, for example, <a href="https://stackoverflow.com/questions/20844983/what-is-the-best-way-to-calculate-number-of-padding-bytes" rel="noopener noreferrer">https://stackoverflow.com/questions/20844983/what-is-the-best-way-to-calculate-number-of-padding-bytes</a> for other ways to calculate this value.<br /><br />Peter Harris</p></blockquote>