ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent/Impl/Glib.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent/Impl/Glib.pm (file contents):
Revision 1.20 by root, Thu Jul 24 06:31:37 2008 UTC vs.
Revision 1.21 by root, Thu Apr 23 22:44:30 2009 UTC

19light of the world: Glib not only scans all its watchers (really, ALL of 19light of the world: Glib not only scans all its watchers (really, ALL of
20them, whether I/O-related, timer-related or what not) during each loop 20them, whether I/O-related, timer-related or what not) during each loop
21iteration, it also does so multiple times and rebuilds the poll list for 21iteration, it also does so multiple times and rebuilds the poll list for
22the kernel each time again, dynamically even. 22the kernel each time again, dynamically even.
23 23
24On the positive side, Glib generally works correctly, no quarrels there. 24On the positive side, and most importantly, Glib generally works
25correctly, no quarrels there.
25 26
26If you create many watchers (as in: more than two), you might consider one 27If you create many watchers (as in: more than two), you might consider one
27of the L<Glib::EV>, L<EV::Glib> or L<Glib::Event> modules that map Glib to 28of the L<Glib::EV>, L<EV::Glib> or L<Glib::Event> modules that map Glib to
28other, more efficient, event loops. 29other, more efficient, event loops.
29 30
30This module uses the default Glib main context for all it's watchers. 31This module uses the default Glib main context for all its watchers.
31 32
32=cut 33=cut
33 34
34package AnyEvent::Impl::Glib; 35package AnyEvent::Impl::Glib;
35 36
48 my @cond; 49 my @cond;
49 # some glibs need hup, others error with it, YMMV 50 # some glibs need hup, others error with it, YMMV
50 push @cond, "in", "hup" if $arg{poll} eq "r"; 51 push @cond, "in", "hup" if $arg{poll} eq "r";
51 push @cond, "out", "hup" if $arg{poll} eq "w"; 52 push @cond, "out", "hup" if $arg{poll} eq "w";
52 53
53 my $source = add_watch Glib::IO fileno $arg{fh}, \@cond, sub { 54 my $source = add_watch Glib::IO fileno $arg{fh}, \@cond, sub { &$cb; 1 };
54 &$cb;
55 1
56 };
57
58 bless \\$source, $class 55 bless \\$source, $class
59} 56}
60 57
61sub timer { 58sub timer {
62 my ($class, %arg) = @_; 59 my ($class, %arg) = @_;
71 &$cb; 68 &$cb;
72 0 69 0
73 } 70 }
74 : sub { &$cb; 0 }; 71 : sub { &$cb; 0 };
75 72
73 bless \\$source, $class
74}
75
76sub idle {
77 my ($class, %arg) = @_;
78
79 my $cb = $arg{cb};
80 my $source = add Glib::Idle sub { &$cb; 1 };
76 bless \\$source, $class 81 bless \\$source, $class
77} 82}
78 83
79sub DESTROY { 84sub DESTROY {
80 remove Glib::Source $${$_[0]}; 85 remove Glib::Source $${$_[0]};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines