Re: Gtk::io patch



Paolo Molaro wrote:


timeout is best handled with a sub timeout {} as described in the
IO::Socket manpage (ie a setter/getter method). This means that
once you created an IO::Socket::INET, for example, and rebless it to
Gtk::io::INET, you can just use:

        $socket->timeout (NEW_TIMEOUT);


But this doesn´t seem to work with Gtk::io,  the timeout in _sweeper is independent of the IO::Socket timeout 
.

I would be open to making the two mechanisms work together.   Attached is another patch for io.pm that
you may find a little more to your liking.  But I´ve been playing with IO::Socket::timeout for a couple of 
hours now and

I cannot make anything timeout through that mechanism.  This patch doesn´t so much work with it as override 
it.

What do you think?  (oh and have a nice weekend)

Jim









as you would do with any other socket. You can just have it change
the global setting, but you'll get extra points if you'll make
the setting per-socket.

As for pending, it would be nice to have a couple of extra methods to
query if there is some action pending on the socket or to remove
a request.

sub is_pending {
        my ($socket, $cond) = @_;
        # $cond can be 'read' or 'write', if not given checks for both
        ...
        # returns the condition pending (again, read, write or both)
        # returns undef if not pending
}

sub cancel_request {
        my ($socket, $cond) = @_;
        # again, $cond is optional and works as above
}

lupus


I didn´t  need to expose the pending structure.
Index: io.pm
===================================================================
RCS file: /cvs/gnome/gnome-perl/Gtk/io.pm,v
retrieving revision 1.1
diff -u -r1.1 io.pm
--- io.pm       2001/01/07 18:19:30     1.1
+++ io.pm       2001/07/13 20:19:38
@@ -1,9 +1,24 @@
 package Gtk::io;
+#use IO::Socket;
+use strict;
 
-my %pending = ();
+my  %pending = ();
 my $sweepid;
 my $timeout = 2;
 
+sub timeout {
+  my($self,$val) = @_;
+
+  my $prevtimeout = $timeout;
+  if($val>0){
+        $timeout = $val;
+        $self->IO::Socket::timeout($val);
+  }else{
+        $self->IO::Socket::timeout($timeout);
+  }
+  $prevtimeout;
+}
+
 sub get_pending {
        my $fd = shift;
        if (defined $fd) {
@@ -20,7 +35,7 @@
                while ( ($k, $v) = each %pending) {
                        next unless ref $v;
                        if ($now - $v->[1] > $timeout) {
-                               warn "Timeout on $k\n";
+                               warn "Timeout on $k after $timeout seconds\n";
                                Gtk::Gdk->input_remove($v->[0]);
                                $pending{$k} = undef;
                        }
@@ -83,10 +98,18 @@
 }
 
 package Gtk::io::INET;
+use IO::Socket::INET;
+use vars qw(@ISA);
 @ISA = qw(Gtk::io IO::Socket::INET);
+
 package Gtk::io::UNIX;
+use IO::Socket::UNIX;
+use vars qw(@ISA);
 @ISA = qw(Gtk::io IO::Socket::UNIX);
+
 package Gtk::io::Pipe;
+use IO::Pipe;
+use vars qw(@ISA);
 @ISA = qw(Gtk::io IO::Pipe);
 1;
 


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