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

Juan Lao Tebar nitzing at gmail.com
Fri Oct 30 14:26:00 PDT 2015


Thanks Uli, I already implemented the idea and it works!

Bart, I'm sorry, but due to the logic of my program, my callbacks *cannot*
be called until it is ready in each loop.

I know that I can implement a complex system of callback stacks to be able
to do this with multithreads, but... for what? It's more simple to poll for
responses when my program is ready to receive answers.

Greetings and thanks for the help guys!
Juan

2015-10-29 18:38 GMT+01:00 Bart Massey <bart at cs.pdx.edu>:

> Use threads! This will work ever so much easier and more reliably if you
> let the xcb code run in a separate thread that can block
>
> On Thu, Oct 29, 2015, 10:36 Uli Schlachter <psychon at znc.in> wrote:
>
>> 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.
>> _______________________________________________
>> Xcb mailing list
>> Xcb at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/xcb
>
>
> _______________________________________________
> Xcb mailing list
> Xcb at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/xcb
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/xcb/attachments/20151030/9c79e586/attachment.html>


More information about the Xcb mailing list