Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!inria!mirsa!daniel From: daniel@mirsa.inria.fr (Daniel Dardailler) Newsgroups: comp.windows.x Subject: XSelectNextEvent() Message-ID: <134@mirsa.inria.fr> Date: 27 Feb 89 13:23:14 GMT Reply-To: daniel@mirsa.inria.fr (Daniel Dardailler) Organization: Bull Research Center. Sophia Antipolis. France Lines: 84 Xlib problem: I want to wait for X events from more than one X server. (it's for a communication program named xtalk, which act basically like the unix-talk but with the X protocol and windows/mouse convenience: independent window, drawing facility, talk with several persons...) The following loop is very time consuming (for 2 displays): do { if (QLength(dpy1)) { XNextEvent(dpy1,&ev1); DealWith(dpy1,&ev1); } if (QLength(dpy2)) { XNextEvent(dpy2,&ev2); DealWith(dpy2,&ev2); } } while (1) ; If there is no event coming from dpy1 or dpy2, the Qlength test always returns False(0) and the loop is VERY active. It seems to me, after many trials, that this loop activity creates 'black hole'/'dead lock' problems on the client side. A loop like: do { XSelectNextEvent(dpy_list, n_dpy, &ev, &disp); /* Blocking */ DealWith(disp,&ev); } while (1) would be better. Have I missed something in the Xlib doc? If not, I already think of a code implementation: XSelectNextEvent(dpy_list, n_dpy, pev, pdisp) Display ** dpy_list ; int n_dpy ; XEvent * pev ; Display * pdisp ; { /** Loop for setting the appriopriate file descriptor in a read mask **/ for (i = 0, dpy = *dpy_list; i < n_dpy; i++) { BITSET(r_mask, dpy->fd); dpy++; } /** Multiple wait on these connections : blocking **/ select(MAXSOCK, r_mask, NULL, NULL, NULL); /** Search for the display ready to be read **/ for (i = 0, dpy = *dpy_list; i < n_dpy; i++) { if (r_mask | dpy->fd) { *pdisp = dpy ; break ; } else dpy++; } /** Now read X event from this connection **/ XNextEvent(*pdisp,pev); } but I'm not a socket hacker, and there are certainly problems I don't see. If such a call already exist in netland, I'd like to get it. These problems will occur in all the situations where one X client is managing the interface for more than one user: talk, chess-like games... Perhaps one could think that this situation must never happened. All comments and ideas on this issue are wellcome. Daniel Dardailler | Email : daniel@mirsa.inria.fr BULL Centre de Sophia Antipolis | Phone : (33) 93 65 77 71 2004, Route des Lucioles | Telex : 97 00 50 F 06565 Valbonne CEDEX France | Fax : (33) 93 65 77 66 -- Daniel Dardailler | Email : daniel@mirsa.inria.fr BULL Centre de Sophia Antipolis | Phone : (33) 93 65 77 71 2004, Route des Lucioles | Telex : 97 00 50 F 06565 Valbonne CEDEX France | Fax : (33) 93 65 77 66