Re: gdk_input_add



Hello,

    I'm using gdk_input_add to get notified about three
events. One of these events occurs as much as 20 times in a
second, but service time is often longer than 50ms. On the other
hand, the two other events occur less frequently.

Do events accumulate on a pending list or similar?
Is there any way to make sure that I am not missing any of the
"low freq" events, and that they are handled in the correct
order?


For gdk_input_add(), you shouldn't ever miss any events. i.e. your
callback will always get called if there's data. However there are no
real guarantees about order or granularity I don't believe.  poll() is
the system call used to implement the main loop which just waits on
multiple file descriptors. If when entering the poll() call more than
one descriptor is already ready for reading, poll() will immediately
return and input handlers for each descriptor will be called. You
could have any amount of data on each descriptor and any number of
descriptors ready for reading at that point.

Ok. So, just to make sure I got the idea, it's kind of:

fd_set set;
struct timeval t;
int n;

FD_ZERO(&set);
FD_SET(fd1, &set);
FD_SET(fd2, &set);
FD_SET(fd3, &set);
  ...
FD_SET(fdN, &set);

t.tv_sec = 0;
t.tv_usec = 0;


while (<loop condition>) {

   /*Assuming fdN is the highest descriptor */
   n = select(fdN+1, &set, NULL, NULL, &t);
   if (n>0) {
      if (FD_ISSET(fd1, &set)) {
         fd1_handler ();
      }

      if (FD_ISSET(fd2, &set)) {
         fd2_handler ();
      }

      if (FD_ISSET(fd3, &set)) {
         fd3_handler ();
      }

      .....

      if (FD_ISSET(fdN, &set)) {
         fd2_handler ();
      }
   } else {
      /* Either timeout or error */
   }
}


Is there any way I can force the order of the
"FD_ISSET (fdN, &set)" conditions?

Is this related to the order of the gdk_input_add() calls?

Should I care about XtAppPeekEvent(), XtAppPending(),
XtAppNextEvent(), XtDispatchEvent(&event), etc, or is this
handled in the main loop of GTK?

Thank you,
Matias.

PS: please cc.





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]