[comp.windows.x] Blocked and Non-Blocked Event Handling in X

sandeep@pulse.UUCP (Sandeep Mehta) (08/25/87)

Once again I ran into some grey areas with X. The XNextEvent and XWindowEvent
routines are blocking routines. Thus if the event queues are empty or dont
have the event specified by the mask, they block waiting for an appropriate
event . To escape that , there is a non-blocking  XCheckWindowEvent routine,
which does'nt seem to return if it doesn't find the masked event !!

Here is the scenario: My event loop has to take care of two events. It reads
from a pipe which is a blocking read too, so I do a ioctl(fd,FIONREAD,&count)
before a read to see if there is any data buffered. Then I need to check to see
if there are any ButtonEvents or ExposeWindow Events take appropriate action,
and go back to reading the pipe for more data !! Thus XCheckWindowEvent seems
to be a nice way out. However I cant seem to fall out of that event check.

I poked into the XChkWinEvent.c file to see what was happening, and it seems
to be stuck in the 
        for ( prev = NULL, qelt = dpy->head; qelt && (qelt->event.window ......
loop. Therefore I assumed that it goes on until the end of list or till the
event is found ... it did'nt !!!! 

Is there a problem with XFlushing the event queue, before calling this routine
or with the mask ? I even tried different masks to make sure.

Would appreciate any help in this regard, till then I am stuck with blocked
XNextEvent() (:-() (:-()

Thanks in advance

sandeep 

***********************************************************************
Sandeep Mehta
Lab for Laser Energetics
Univ. of Rochester.

Tel. (716)-427-2379 (H)
     (716)-275-5101 (W)

ARPA: sandeep@pulse.lle.rochester.edu
UUCP: {allegra,seismo}!rochester!pulse!sandeep
BITNET: snm1237@ritvaxa.BITNET
***********************************************************************
Disclaimer: Language is a Virus .... (Laurie Anderson)
***********************************************************************
Newsgroups: comp.windows.x
Subject: Blocked and Non-Blocked Event Handling in X
Expires: 
References: 
Sender: 
Reply-To: sandeep@ur-laser.UUCP (Sandeep Mehta)
Followup-To: 
Distribution: 
Organization: Laboratory for Laser Energetics, U. of R., Rochester, NY
Keywords: 


Once again I ran into some grey areas with X. The XNextEvent and XWindowEvent
routines are blocking routines. Thus if the event queues are empty or dont
have the event specified by the mask, they block waiting for an appropriate
event . To escape that , there is a non-blocking  XCheckWindowEvent routine,
which does'nt seem to return if it doesn't find the masked event !!

Here is the scenario: My event loop has to take care of two events. It reads
from a pipe which is a blocking read too, so I do a ioctl(fd,FIONREAD,&count)
before a read to see if there is any data buffered. Then I need to check to see
if there are any ButtonEvents or ExposeWindow Events take appropriate action,
and go back to reading the pipe for more data !! Thus XCheckWindowEvent seems
to be a nice way out. However I cant seem to fall out of that event check.

I poked into the XChkWinEvent.c file to see what was happening, and it seems
to be stuck in the 
        for ( prev = NULL, qelt = dpy->head; qelt && (qelt->event.window ......
loop. Therefore I assumed that it goes on until the end of list or till the
event is found ... it did'nt !!!! 

Is there a problem with XFlushing the event queue, before calling this routine
or with the mask ? I even tried different masks to make sure.

Would appreciate any help in this regard, till then I am stuck with blocked
XNextEvent() (:-() (:-()

Thanks in advance

sandeep 

***********************************************************************
Sandeep Mehta
Lab for Laser Energetics
Univ. of Rochester.

Tel. (716)-427-2379 (H)
     (716)-275-5101 (W)

ARPA: sandeep@pulse.lle.rochester.edu
UUCP: {allegra,seismo}!rochester!pulse!sandeep
BITNET: snm1237@ritvaxa.BITNET
***********************************************************************
Disclaimer: Language is a Virus .... (Laurie Anderson)
***********************************************************************

haynes@DECWRL.DEC.COM (08/26/87)

Use XPending to do a non-blocking check for recieved X events.

Use select on the file descriptor in the display structure to wait for
input from multiple sources.

	-- Charles

Rick.Busdiecker@h.gp.cs.cmu.EDU (08/27/87)

Use XPending to check for new events.  You shoudl also be able use
select(2) on the file descriptor for the display, but I haven't used
this.

			Rick

zyg@geovision.UUCP (Zygmunt Wiercioch) (09/01/87)

Using select on the display file descriptor ( dpyno() ) works just fine.
We have a similar implementation: a display list process receiving data 
via a socket and also handling X events.

The only problem is the overhead in the select call.  You should send
as much as possible down the pipe and process it before doing the select.
I have found that if the amount of data to process was small, up to
70% of the time was spent handling the select/read loop.  Buffering the
requests made a big difference.
-- 
 Zygmunt Wiercioch    UUCP: ...!utzoo!dciem!nrcaer!cognos!geovision!zyg