[comp.windows.x] Xlib event loop for 2 servers from single client ?

jmd@wrkgrp.uucp (Joseph M DeAngelo) (01/11/91)

I just got a program to handle a board game for 2 players on different servers.
It's written in Xlib ( not Xt ).  To permit input from either player at any
time this program loops looking for events from either server using 
XEventsQueued.  This polling process consumes vast amounts of processor
resource.  I wrote to the author but his response was to put a 'usleep'
wait in the loop.  Is there any facility in Xlib to wait for an event from
either server?

-- 
what is life but the taking of chances???

jg@crl.dec.com (Jim Gettys) (01/11/91)

No, not in Xlib.

The way you do what you want is get the file descriptor "fileno(dpy)",
and then make sure everything has been flused before calling the "select"
(on BSD derived systems; Sys V has "poll" instead, though many system V
based systems out there provide select.).

kaleb@thyme.jpl.nasa.gov (Kaleb Keithley) (01/11/91)

In article <1991Jan10.220308.5385@crl.dec.com> jg@crl.dec.com (Jim Gettys) writes:
>
>The way you do what you want is get the file descriptor "fileno(dpy)",

Display is not a stream, fileno on dpy won't give you what you want.
What you want is dpy->fd.

-- 
Kaleb Keithley                      Jet Propulsion Labs
kaleb@thyme.jpl.nasa.gov

Offensive quote coming soon to a .signature file near you.

klee@wsl.dec.com (Ken Lee) (01/11/91)

|> The way you do what you want is get the file descriptor "fileno(dpy)",

The X macro ConnectionNumber does the right thing here.  Note that the
application contexts in the X Toolkit also manage multiple displays.

-- 
Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@wsl.dec.com
uucp: uunet!decwrl!klee

jg@quabbin.crl.dec.com (Jim Gettys) (01/11/91)

In article <1991Jan10.191312@wsl.dec.com> klee@wsl.dec.com writes:
>|> The way you do what you want is get the file descriptor "fileno(dpy)",
>
>The X macro ConnectionNumber does the right thing here.  Note that the
>application contexts in the X Toolkit also manage multiple displays.
>

I stand corrected by all the young upstarts out there... :-).  Shows we
all have our off days...
				- Jim
--
Digital Equipment Corporation
Cambridge Research Laboratory

ea08+@andrew.cmu.edu (Eric A. Anderson) (01/12/91)

It would be best to use ConnectionNumber(dpy), which is a macro that
gets you the file descriptor, so that you can do a select on it.
It might be good to put the info on how to do connections with
multiple servers into the FAQ, becuase I have seen a number of
questions recently about it.  eg, how to do it in Xt, how to do it in
xlib should cover all the bases, also programs like xtank as pointers
for people to look at.
         -Eric
*********************************************************
"My life is full of additional complications spinning around until
 it makes my head snap off."
           -Unc. Known.
"You are very smart, now shut up."
           -In "The Princess Bride"
*********************************************************