Newsgroups: comp.windows.x
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!snorkelwacker.mit.edu!bloom-beacon!dont-send-mail-to-path-lines
From: mouse@lightning.mcrcim.mcgill.EDU (der Mouse)
Subject: Re:  Xt Input Callbacks
Message-ID: <9105090219.AA02229@lightning.McRCIM.McGill.EDU>
Sender: daemon@athena.mit.edu (Mr Background)
Organization: The Internet
Date: 9 May 91 02:19:19 GMT
Lines: 41

> Why do read callbacks installed with XtAddInput() get called when
> there is no input pending?

"Just because" - that's simply the way it is.  In essence, your
callback is called whenever a read() would not block.  Whether there is
actually anything available to be read is more or less irrelevant.

You are probably trying to use XtAddInput on a file.  This doesn't work
the way you probably expect it to.  Here's the relevant item from the
FAQ.  It talks about XtAppAddInput, but the difference between that and
XtAddInput is irrelevant here.

----------------------------------------------------------------------
Subject: 103)  Why does XtAppAddInput not work as described?
I am using XtAppAddInput to read from a file, but the function is called even
when there isn't input pending.

	XtAppAddInput is actually working as it is supposed to. When used on
files, it is called whenever the file is READY to be read, not when there is
new data to be read. The file is almost always ready to be read, however, if 
only because you can spin back to the beginning and read data you've read 
before. The result is that your function will almost always be called every
time around XtMainLoop().
	To get the type of interaction you are expecting, add this line to
the beginning of your function to test whether there is new data:
	     if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) return;

[courtesy Dan Heller (argv@ora.com); 8/90]

----------------------------------------------------------------------

I would add a comment that the fix suggested is probably not a good
idea, as the application will effectively busy-wait; even when nothing
is happening, it will be spinning around in a loop, chewing up cycles
and syscalls at a high rate.  You're probably better off setting up a
timer event and checking the file when it goes off.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu
