argv@turnpike.Eng.Sun.COM (Dan Heller) (08/10/90)
In article <726@beguine.UUCP> Paul.Quane@samba.acs.unc.edu (BBS Account) writes: > 2/ I have tried using XtAppAddInput with the XtInputReadMask. The callback > procedure was called every time round XtMainLoop, not just when > Input was pending on the file. Why doesn't it work as described. What > am I doing wrong? ( I opened the file with open ) This should be added to the list of "frequently asked questions". XtAppAddInput() when used on *files* will almost always cause the associated function to be called. The problem that most people have is that they misinterpret the meaning of the function -- it does *not* mean that the function is called whenever the file has "new data" to read, it means that the function will be called whenever the file is *ready* to be read. Which, in most cases, is all the time. Just because there is no new data to read does not imply that you can't rewind the file and read it again ... thus, the file is still "ready to be read." To get the type of interaction you're expecting, you should add the following two lines to the beginning of your function: if (ioctl(fd, FIONREAD, &n) == -1 || n == 0) return; This tests to see if there is any data on the file descriptor that is ready to be read (that you haven't read yet). If there is nothing new to read, n will equal zero. -- dan ---------------------------------------------------- O'Reilly && Associates argv@sun.com / argv@ora.com Opinions expressed reflect those of the author only.