Re: How to properly discard socket-handoff GetInputFocus requests?

Uli Schlachter <[email protected]>
Newsgroups gmane.comp.freedesktop.xcb
Message-ID <[email protected]>
On 26.02.2018 09:07, Clemens Eisserer wrote:
> Hi Uli,
> 
>> The last argument to xcb_take_socket gives you the sequence number. It
>> is just the number of requests that were sent on the connection. So the
>> sequence number of the first request that you generate on your own is
>> <that number> + 1, etc.
> 
> Strange, I tried calling xcb_discard_reply64(sent + 1) and it didn't work.

How do you determine that? It seems to work for me (see the attached
program which sends two GetInputFocus requests via xcb_writev() and
discards the first reply, then uses xcb_poll_for_reply64() to test if
this really worked).

Cheers,
Uli
-- 
"Do you know that books smell like nutmeg or some spice from a foreign
land?"
                                              -- Faber in Fahrenheit 451

_______________________________________________
Xcb mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/xcb
test.c (text/x-csrc, 1.5 KB)
#include <stdio.h>
#include <stdlib.h>
#include <xcb/xcb.h>
#include <xcb/xcbext.h>

static void return_socket(void *unused) {
	(void) unused;
	puts("returning socket");
}

int main() {
	uint64_t sent;
	xcb_connection_t *c;
	xcb_get_input_focus_request_t get_input_focus;
	struct iovec parts[2];
	int first, second;
	void *first_r, *second_r;

	get_input_focus.major_opcode = XCB_GET_INPUT_FOCUS;
	get_input_focus.pad0 = 0;
	get_input_focus.length = sizeof(get_input_focus) / 4;

	parts[0].iov_base = (char*) &get_input_focus;
	parts[1].iov_base = (char*) &get_input_focus;
	parts[0].iov_len = sizeof(get_input_focus);
	parts[1].iov_len = sizeof(get_input_focus);

	c = xcb_connect(NULL, NULL);
	xcb_take_socket(c, return_socket, NULL, 0, &sent);

	printf("Got sent=%d\n", (int) sent);

	/* Send two GetInputFocus requests */
	xcb_writev(c, &parts[0], 2, 2);

	/* Discard the reply for the first request */
	xcb_discard_reply64(c, sent + 1);

	/* return the socket and do a sync, so that the replies to the above
	 * requests already arrived.
	 */
	free(xcb_get_input_focus_reply(c, xcb_get_input_focus(c), NULL));

	/* Now poll for the replies to the requests we sent earlier */
	first_r = second_r = NULL;
	first = xcb_poll_for_reply64(c, sent + 1, &first_r, NULL);
	second = xcb_poll_for_reply64(c, sent + 2, &second_r, NULL);

	printf("First  reply: %d %p\n", first, first_r);
	printf("Second reply: %d %p\n", second, second_r);
	free(first_r);
	free(second_r);

	xcb_disconnect(c);
	return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.