XFree86 and ConnectionNumber - Xwindows

This is a discussion on XFree86 and ConnectionNumber - Xwindows ; I'm trying to use ConnectionNumber (and also tried Display->fd) to get a file descriptor that I can select on to multiplex input from several different sources. The problem I'm having is that I never get any activity on the fd ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: XFree86 and ConnectionNumber

  1. XFree86 and ConnectionNumber

    I'm trying to use ConnectionNumber (and also tried Display->fd) to
    get a file descriptor that I can select on to multiplex input from
    several different sources. The problem I'm having is that I never
    get any activity on the fd (and it's strangely low-numbered -- it's
    apparently the actual connection number, not a file descriptor).
    I am sure to only call select if XPending(disp) == 0.

    Is XFree using shared memory for IPC so I don't have an fd to select() on?
    I've tried setting the XLOCAL env var to NAMED to force it to use
    named pipes to no avail.

    The application is an OpenGL graphics server. It works great. It
    uses hardware for all graphics operations, window compositing, and
    selection. I've added features such as an image cache and TrueType
    font rendereing with FreeType. Coming from an X background, I use
    a similar set of Pointer/Button events to send to clients and other
    operations such as grabs. All windows are double-buffered so you
    never see "exposed" windows like in X, even during resizing. Alpha
    values can propogated up the window hierarchy so all,part, or none
    of an app will be transparent.

    The only problem I have now is my server is wasting CPU cycles polling
    for XEvents (my clients & server use named pipes for IPC). Any know how
    I can get a file descriptor? I'm using XFree86 4.3.

    Thanks,
    Mike

  2. Re: XFree86 and ConnectionNumber

    ConnectionNumber() is indeed the way to get a select()able file descriptor.
    You have to have a specific window event mask set (I don't remember which
    one) for this to work. Here are the event masks I use, and I am able to
    select() from the X event queue.

    m_lWindowEventMasks = KeyPressMask |
    KeyReleaseMask |
    ButtonPressMask |
    ButtonReleaseMask |
    EnterWindowMask |
    LeaveWindowMask |
    PointerMotionMask |
    KeymapStateMask |
    ExposureMask |
    VisibilityChangeMask |
    StructureNotifyMask |
    // ResizeRedirectMask |
    SubstructureNotifyMask |
    SubstructureRedirectMask|
    FocusChangeMask |
    PropertyChangeMask |
    ColormapChangeMask |
    OwnerGrabButtonMask;


    Michael Dreesen wrote:

    > The only problem I have now is my server is wasting CPU cycles polling
    > for XEvents (my clients & server use named pipes for IPC). Any know how
    > I can get a file descriptor? I'm using XFree86 4.3.



  3. Re: XFree86 and ConnectionNumber

    In comp.windows.x, Michael Dreesen

    wrote
    on Wed, 31 Dec 2003 21:27:51 GMT
    :
    > I'm trying to use ConnectionNumber (and also tried Display->fd) to
    > get a file descriptor that I can select on to multiplex input from
    > several different sources. The problem I'm having is that I never
    > get any activity on the fd (and it's strangely low-numbered -- it's
    > apparently the actual connection number, not a file descriptor).
    > I am sure to only call select if XPending(disp) == 0.
    >
    > Is XFree using shared memory for IPC so I don't have an fd to select() on?
    > I've tried setting the XLOCAL env var to NAMED to force it to use
    > named pipes to no avail.
    >
    > The application is an OpenGL graphics server. It works great. It
    > uses hardware for all graphics operations, window compositing, and
    > selection. I've added features such as an image cache and TrueType
    > font rendereing with FreeType. Coming from an X background, I use
    > a similar set of Pointer/Button events to send to clients and other
    > operations such as grabs. All windows are double-buffered so you
    > never see "exposed" windows like in X, even during resizing. Alpha
    > values can propogated up the window hierarchy so all,part, or none
    > of an app will be transparent.
    >
    > The only problem I have now is my server is wasting CPU cycles polling
    > for XEvents (my clients & server use named pipes for IPC). Any know how
    > I can get a file descriptor? I'm using XFree86 4.3.
    >
    > Thanks,
    > Mike


    There are some caveats when using select().

    1. You need to pass in 1 plus your highest fid. See the select()
    manpage. Also bear in mind that adding new fids to your system
    may require this number to change.

    2. Select() is inherently destructive in its fd_sets. You need to
    rebuild them (or copy them from somewhere else) every time.
    Depending on OS you may also need to rebuild your timeout value
    (Linux in particular modifies it; it's not clear whether other
    operating systems do or not).

    3. It sounds like your using XPending() prior to calling select().
    This is, AFAIK, quite proper.

    ConnectionNumber() will be fairly low as the standard
    program running X will most likely open X first, which
    means 0,1, and 2 are the standard in/out/err, and X will
    probably get 3 in that case (I'd have to play with it).
    Changing its meaning will break a fair number of programs.

    I'm not having a problem with select() on a 4.1 OpenGL-capable server
    (although the actual capabilities are a little on the slow side;
    it's old hardware :-) ).

    --
    #191, ewill3@earthlink.net
    It's still legal to go .sigless.

  4. Re: XFree86 and ConnectionNumber

    Consider also using XAddConnectionWatch or XInternalConnectionNumbers,
    to detect any internal connections opened by Xlib.

  5. Re: XFree86 and ConnectionNumber

    In comp.windows.x, Kalle Olavi Niemitalo

    wrote
    on Thu, 01 Jan 2004 14:03:46 +0200
    <87k74beuzh.fsf@Astalo.kon.iki.fi>:
    > Consider also using XAddConnectionWatch or XInternalConnectionNumbers,
    > to detect any internal connections opened by Xlib.


    Ye gods. When did *this* happen?

    Is this connected with input methods or what? Color me curious.

    --
    #191, ewill3@earthlink.net
    It's still legal to go .sigless.

  6. Re: XFree86 and ConnectionNumber

    Thanks everyone. I guess I've forgotten a few things about select()
    since I last used it (in operating systems class years ago). I hope
    to have a cool open-source GL-based graphics server for everyone soon


    Cheers,
    Mike


    The Ghost In The Machine wrote in message news:...
    > In comp.windows.x, Michael Dreesen
    >
    > wrote
    > on Wed, 31 Dec 2003 21:27:51 GMT
    > :
    > > I'm trying to use ConnectionNumber (and also tried Display->fd) to
    > > get a file descriptor that I can select on to multiplex input from
    > > several different sources. The problem I'm having is that I never
    > > get any activity on the fd (and it's strangely low-numbered -- it's
    > > apparently the actual connection number, not a file descriptor).
    > > I am sure to only call select if XPending(disp) == 0.
    > >
    > > Is XFree using shared memory for IPC so I don't have an fd to select() on?
    > > I've tried setting the XLOCAL env var to NAMED to force it to use
    > > named pipes to no avail.
    > >
    > > The application is an OpenGL graphics server. It works great. It
    > > uses hardware for all graphics operations, window compositing, and
    > > selection. I've added features such as an image cache and TrueType
    > > font rendereing with FreeType. Coming from an X background, I use
    > > a similar set of Pointer/Button events to send to clients and other
    > > operations such as grabs. All windows are double-buffered so you
    > > never see "exposed" windows like in X, even during resizing. Alpha
    > > values can propogated up the window hierarchy so all,part, or none
    > > of an app will be transparent.
    > >
    > > The only problem I have now is my server is wasting CPU cycles polling
    > > for XEvents (my clients & server use named pipes for IPC). Any know how
    > > I can get a file descriptor? I'm using XFree86 4.3.
    > >
    > > Thanks,
    > > Mike

    >
    > There are some caveats when using select().
    >
    > 1. You need to pass in 1 plus your highest fid. See the select()
    > manpage. Also bear in mind that adding new fids to your system
    > may require this number to change.
    >
    > 2. Select() is inherently destructive in its fd_sets. You need to
    > rebuild them (or copy them from somewhere else) every time.
    > Depending on OS you may also need to rebuild your timeout value
    > (Linux in particular modifies it; it's not clear whether other
    > operating systems do or not).
    >
    > 3. It sounds like your using XPending() prior to calling select().
    > This is, AFAIK, quite proper.
    >
    > ConnectionNumber() will be fairly low as the standard
    > program running X will most likely open X first, which
    > means 0,1, and 2 are the standard in/out/err, and X will
    > probably get 3 in that case (I'd have to play with it).
    > Changing its meaning will break a fair number of programs.
    >
    > I'm not having a problem with select() on a 4.1 OpenGL-capable server
    > (although the actual capabilities are a little on the slow side;
    > it's old hardware :-) ).


  7. Re: XFree86 and ConnectionNumber

    The Ghost In The Machine writes:

    > Ye gods. When did *this* happen?


    There is a comment in xc/lib/X11/XlibInt.c, above
    _XRegisterInternalConnection:

    /*
    * Support for internal connections, such as an IM might use.
    * By Stephen Gildea, X Consortium, September 1993
    */

    > Is this connected with input methods or what?


    If I grepped correctly, it is not used for anything else;
    _XRegisterInternalConnection is only ever called from
    xc/lib/X11/xlibi18n/im/ximcp/imTrans.c.

    There is also IceAddConnectionWatch, but I suppose people who use
    ICE know about that.

+ Reply to Thread