[Xcb] Help with external socket handling and xcb

Uli Schlachter psychon at znc.in
Sat Sep 25 09:12:09 UTC 2021


Hi,

Am 09.09.21 um 12:48 schrieb Carlo Wood:
> Just to be clear; so this means that in order for xcb_poll_for_event
> to work while only calling it when I see that the fd is readable, I only
> ever have to monitor that the fd is readable, and never have to worry
> about monitoring if the fd is writable, because all writing is done
> blocking, even though the fd itself is non-blocking?

Attached is a short example based on the code that I already linked to
elsewhere. This code sends some requests and non-blockingly waits for
the replies (via poll()). When poll() indicates a timeout, some more
requests are sent just so that the example does something.

The important bits are: Whenever anything used the xcb connection (in
this case: through xcb_get_input_focus()), this calls both xcb_flush()
(to (blockingly - sorry) send the new requests) and
dispatch_replies()/xcb_poll_for_reply() to check whether new replies
were received. The later is necessary since both xcb_get_input_focus()
(sending a request) and xcb_flush() (flushing the output buffer) might
read from the fd.

Put differently: We always have to check whether the fd is readable *or*
some replies are already pending.

This example does not deal with events, but that is just one
xcb_poll_for_event() away.

I hope this helps,
Uli
-- 
I'd be delighted to offer any advice I can. When I have some, I'll let
you know.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.c
Type: text/x-csrc
Size: 3014 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/xcb/attachments/20210925/9b0c1e1d/attachment.c>


More information about the Xcb mailing list