[Xcb] Best way to manage server responses in a non-blocking way?

Uli Schlachter psychon at znc.in
Thu Oct 29 10:27:39 PDT 2015


Hi,

[...]
> So my questions here are:
> 
> 1) Is this the correct way to read events and replies from the server?
> I understand that if I call xcb_poll_for_event when the next response
> is a reply, it will return a NULL. But I'm not sure if I will be able
> to read the reply using xcb_poll_for_reply after that...

XCB never throws away replies/events (unless you tell it to via
xcb_discard_reply()). So yeah, you can just poll for reply after a poll for
event wasn't successful.

Actually, I guess first polling for replies makes more sense...

> 2) I can not find any example of xcb_poll_for_reply on internet. Is
> there any documentation about it? I'm not sure about how to implement
> layer_nextReply, since in XCB there is no "generic" replies. (maybe
> iterating a list of stored cookies doing the propper castings?)
[...]

I was surprised that there is no docs for it... Anyway, this is just
xcb_wait_for_reply() without the waiting part. If no reply and no error was
received yet, it will just return NULL.

Note that you have to make sure that your requests are actually send out before
there can be any reply for them (xcb_flush()). xcb_wait_for_reply()
automatically flushes for you, so this might be easy to miss.

Cheers,
Uli
-- 
If you have to type the letters "A-E-S" into your source code, you're doing it
wrong.


More information about the Xcb mailing list