Re: input_add in infinite loop



On Mon, May 19, 2003 at 07:40:14AM -0700, Ben Bailey wrote:
I've gone through the archives in this list and I
think I even looked through all 300+ hits on google
for "input_add".  And I still can't find a way to keep
input_add from constantly calling my sub.  I know this
is an overly-simple piece of code, but I wanted to
make sure I could use the function before developing
more of my GUI.

My guess is that input_add() uses select(2) to see if the file can be
read without blocking, and a disk file can always be read without
blocking!  Either you get some data or you get EOF, in any case the
process won't block.

You have to read some data or get EOF in your sub, otherwise the sub
will be called forever.

Select(2) and hence input_add(), should only be used with file
descriptors that have a real risk of blocking your process, such as
network connections, terminal input, pipes and other IPC.


I've seen examples where the sub uses input_remove,
but i want to keep looking for the next change in my
file even after finding one.

select(2) doesn't monitor a file for changes.  It monitors a file for
non-blocking reads as described above.


I'm reading a file as a workaround...

That's the problem.

I originally
wanted to monitor an table on a MySQL server.  So if
anyone knows a way to do that instead, that would be
preferable.

You have to poll it regularly.  You can do that with a timeout
callback (timeout_add()).


BTW, I'm using Perl 5.6.0 (from the Redhat 7.2 distro)
and the Gtk-Perl-0.7008-3 RPM from the same source.

I appreciate any thoughts.



#!/usr/bin/perl
# inputadd.plx

use warnings;
use strict;
use Gtk;
init Gtk;

my $updatelog = '/home/metuser/updatelog';

open (TMP, "$updatelog 2>&1 |");

my $id = Gtk::Gdk->input_add(fileno(TMP), 'read',
                               \&changed);
  
  main Gtk;

  sub changed {
      print "File changed\n";    
  }


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

-- 
René Seindal (rene seindal dk)                  http://sights.seindal.dk/




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