klee@wsl.dec.com (Ken Lee) (05/09/91)
In article <1991May8.184621.13022@motcad.portal.com>, jtc@motcad.portal.com (J.T. Conklin) writes: |> Why do read callbacks installed with XtAddInput() get called when there is |> no input pending? Is there any way to stop this from happening? The callback is called when the fd is ready for reading, which is a little different from having input pending. A common error is trying to use XtAddInput on regular UNIX files, which are almost always "ready" for reading, although they may have no new input. -- Ken Lee DEC Western Software Laboratory, Palo Alto, Calif. Internet: klee@wsl.dec.com uucp: uunet!decwrl!klee
mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (05/09/91)
> 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
jmellby@iluvatar.dseg.ti.COM (05/09/91)
John R. Mellby Texas Instruments jmellby@iluvatar.dseg.ti.com P.O.Box 869305, MS 8513 jmellby@skvax1.ti.com Plano, Texas, 75266 (214)517-5370 (214)575-6774 **************************************************************************** * "People ask me: Why do you write about food, and eating and drinking? * * Why don't you write about the struggle for power and security, and * * about love, the way others do? * * They ask it accusingly, as if I were somehow gross, unfaithful * * to the honor of my craft. * * The easiest answer is to say that, like most other humans, I am hungry. * * But there is more than that. It seems to me that our three basic needs, * * for food and security and love, are so mixed and mingled and entwined * * that we cannot straightly think of one without the others. So it * * happens that when I write of hunger, I am really writing about love and * * the hunger for it ... and then the warmth and richness and fine reality * * of hunger satisfied ... and it is all one. * * -- M. F. K. Fisher "The Art of Eating" * ****************************************************************************
jmellby@iluvatar.dseg.ti.COM (05/09/91)
I'm sorry about the previous message. My finger slipped and I didn't really mean to reply to your message. Oops John R. Mellby Texas Instruments jmellby@iluvatar.dseg.ti.com P.O.Box 869305, MS 8513 jmellby@skvax1.ti.com Plano, Texas, 75266 (214)517-5370 (214)575-6774 **************************************************************************** * "People ask me: Why do you write about food, and eating and drinking? * * Why don't you write about the struggle for power and security, and * * about love, the way others do? * * They ask it accusingly, as if I were somehow gross, unfaithful * * to the honor of my craft. * * The easiest answer is to say that, like most other humans, I am hungry. * * But there is more than that. It seems to me that our three basic needs, * * for food and security and love, are so mixed and mingled and entwined * * that we cannot straightly think of one without the others. So it * * happens that when I write of hunger, I am really writing about love and * * the hunger for it ... and then the warmth and richness and fine reality * * of hunger satisfied ... and it is all one. * * -- M. F. K. Fisher "The Art of Eating" * ****************************************************************************