[Xcb] Foreign file descriptors

Russell Shaw rjshaw at netspace.net.au
Wed Sep 27 09:03:58 PDT 2006


Jamey Sharp wrote:
> On Wed, Sep 27, 2006 at 02:39:01PM +1000, Russell Shaw wrote:
> 
>>Hi,
> 
> Hi Russell!
> 
>>To monitor external file descriptors for things like receiving
>>characters on a serial port, xlib doesn't seem to have any facility
>>for that, so your application remains stuck in XNextEvent().
>>
>>Does xcb have a way around this?
> 
> No, that's outside XCB's scope. But with both Xlib and XCB, you can get
> the file descriptor of the X connection and use select(2) or poll(2).
> This is somewhat non-trivial to get right, though. I've been meaning to
> work out what the application has to do to get this right, but haven't
> gotten around to it yet.

Hi,
I tried:

   get_X_connection_fd;
   while(1) {
       poll(...);
       if(fd_is_X_or_X_IM_and_is_ready_for_reading) {
           XNextEvent(...);  /* should not block */
           handle_X_event(...);
       }
       else if(fd_is_non_X) {
           handle_our_own_fd_event(...);
       }
       ...
   }

However, it didn't work because inside XNextEvent() (_XReadEvents(dpy)),
events are held in queues, and adding XSync() and XFlush() around it didn't
help.

However, i could use _XRegisterInternalConnection() which adds your own IM file
descriptors and callbacks, but there is no public X function for that unless you
use XlibInt.h directly.

> Of course, what we actually recommend is using threads. That may be a
> bad idea with Xlib, but XCB is designed to support threads transparently.

Ok. Threads are something i'll think about:)


More information about the Xcb mailing list