[comp.windows.x] Folllowup question:MULTIPLE servers

narayan@cs.iastate.edu (Pankaj Narayan) (01/16/90)

>From comp.windows.x Mon Jan 15 12:29:08 1990
>From: rws@EXPO.LCS.MIT.EDU (Bob Scheifler)
>Date: 13 Jan 90 16:36:07 GMT
>Subject: Re: Questions: mutiple servers poss.??


>>	but here I want to put EACH window on a different
>>	display----choose 3 servers within one program, as it were.

>You haven't stated whether you are using Xlib or some toolkit.  At the
>Xlib level, you can simply call XOpenDisplay more than once, using a
>different display string each time, to connect to more than one display.
>You'll have to invent some mechanism, like special command line options,

	I did that, but then get stuck at the while loop where I
	wait for expose events etc.

	while (1) {
	  XGetNextEvent(display, &event)
	  switch (event) {

		case Expose:

	...
	etc...

	} /*of while*/

	Basically, I can't get to call XGetNextEvent(display_1, &event)
	for each of the windows (i.e displays) in PARALLEL. Also, I can't
	call them one after another, since if I have


	XGetNextEvent(display_1, &event_1);
	XGetNextEvent(display_2, &event_2);

	and there is no event on display_1 while lots of events were
	being generated on display_2, then this would bomb.

	Any suggestions ?

	pankaj narayan
	iowa state univ

black@masscomp.ccur.com (Sam Black) (01/16/90)

>	Basically, I can't get to call XGetNextEvent(display_1, &event)
>	for each of the windows (i.e displays) in PARALLEL.

There are at least three ways to get around this.  If your system supports
select, and your server communications mechanism also does (such as sockets),
you can do something like:

	for (;;)
	{
		unsigned long mask;

		mask = ((1 << ConnectionNumber(dpy1)) |
			(1 << ConnectionNumber(dpy2)) |
			(1 << ConnectionNumber(dpy3)));

		if (select(3, &mask, NULL, NULL, NULL) != -1)
		{
			if (mask & (1 << ConnectionNumber(dpy1)))
			{
				XNextEvent(dpy1, &event)
				/* process for connection 1 */
			}

			if (mask & (1 << ConnectionNumber(dpy2)))
			{
				XNextEvent(dpy2, &event)
				/* process for connection 2 */
			}

			if (mask & (1 << ConnectionNumber(dpy3)))
			{
				XNextEvent(dpy3, &event)
				/* process for connection 3 */
			}
		}
	}

To stay entirely within the realm of X, you can do something like:

	for (;;)
	{
		if (XPending(dpy1))
		{
			XNextEvent(dpy1, &event)
			/* process for connection 1 */
		}
		if (XPending(dpy2))
		{
			XNextEvent(dpy2, &event)
			/* process for connection 2 */
		}
		if (XPending(dpy3))
		{
			XNextEvent(dpy3, &event)
			/* process for connection 3 */
		}
	}

or

	for (;;)
	{
		if (XCheckMaskEvent(dpy1, -1, &event))
		{
			/* process for connection 1 */
		}
		if (XCheckMaskEvent(dpy2, -1, &event))
		{
			/* process for connection 2 */
		}
		if (XCheckMaskEvent(dpy3, -1, &event))
		{
			/* process for connection 3 */
		}
	}

--------------------------------------------------------------------------------
I'm pink, therefore I'm Spam.
		     ___________
		    /  ________/__	...!{decvax,uunet}!masscomp!black
		   /__/_______/  /	black@westford.ccur.com
	  Concurrent /__________/
	Computer Corporation
--------------------------------------------------------------------------------

black@masscomp.ccur.com (Sam Black) (01/16/90)

Oops...

>		if (select(3, &mask, NULL, NULL, NULL) != -1)

should be

>		if (select(maxfd, &mask, NULL, NULL, NULL) != -1)

where maxfd is (max(ConnectionNumber(dpy1),
		    max(ConnectionNumber(dpy2),
			ConnectionNumber(dpy3))) + 1)

--------------------------------------------------------------------------------
I'm pink, therefore I'm Spam.
		     ___________
		    /  ________/__	...!{decvax,uunet}!masscomp!black
		   /__/_______/  /	black@westford.ccur.com
	  Concurrent /__________/
	Computer Corporation
--------------------------------------------------------------------------------

net@tub.UUCP (Oliver Laumann) (01/16/90)

In article <6821@masscomp.ccur.com> black@westford.ccur.com (Sam Black) writes:
> Oops...
> 
> >		if (select(3, &mask, NULL, NULL, NULL) != -1)
> 
> should be
> 
> >		if (select(maxfd, &mask, NULL, NULL, NULL) != -1)

Actually it should be

> >		if (select(maxfd, &mask, (int *)0, (int *)0, (int *)0) != -1)

(except when you are using function prototypes).