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.1 by root, Wed Apr 27 01:26:44 2005 UTC vs.
Revision 1.11 by root, Sun Jul 8 08:52:10 2007 UTC

1package AnyEvent::Impl::Glib; 1package AnyEvent::Impl::Glib;
2
3no warnings;
4use strict;
2 5
3use Glib (); 6use Glib ();
4 7
5my $maincontext = Glib::MainContext->default; 8my $maincontext = Glib::MainContext->default;
6 9
7sub new_from_fh { 10sub io {
8 my ($class, $fh) = @_; 11 my ($class, %arg) = @_;
9 bless { fh => $fh }, $class; 12
13 my $self = bless \%arg, $class;
14 my $rcb = \$self->{cb};
15
16 my @cond;
17 # some glibs need hup, others error with it, YMMV
18 push @cond, "in", "hup" if $self->{poll} eq "r";
19 push @cond, "out", "hup" if $self->{poll} eq "w";
20
21 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub {
22 $$rcb->();
23 ! ! $$rcb
24 };
25
26 $self
10} 27}
11 28
12sub cb { 29sub timer {
13 my ($self, $cb) = @_; 30 my ($class, %arg) = @_;
14 $self->{cb} = $cb; 31
15 $self; 32 my $self = bless \%arg, $class;
16} 33 my $cb = $self->{cb};
17 34
18sub poll { 35 $self->{source} = add Glib::Timeout $self->{after} * 1000, sub {
19 my ($self, $r, $w, $e) = @_;
20
21 remove Glib::Source delete $self->{source} if $self->{source};
22
23 my @cond;
24 push @cond, "in" if $r;
25 push @cond, "out" if $w;
26 push @cond, "err" if $e;
27
28 my $cb = \$self->{cb}; # avoid $self-reference
29
30 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub {
31 $$cb->(); 1; 36 $cb->();
37 0
32 }; 38 };
33 39
34 $self; 40 $self
35} 41}
36 42
37sub DESTROY { 43sub DESTROY {
38 my ($self) = @_; 44 my ($self) = @_;
39 45
40 remove Glib::Source delete $self->{source} if $self->{source}; 46 remove Glib::Source delete $self->{source} if $self->{source};
47 # need to undef $cb because we hold references to it
48 $self->{cb} = undef;
49 %$self = ();
41} 50}
42 51
43############# 52sub one_event {
44 53 $maincontext->iteration (1);
45sub new_signal {
46 my $class = shift;
47
48 bless \my $x, $class;
49} 54}
50 55
51sub send { 561
52 ${$_[0]}++;
53}
54 57
55sub wait {
56 $maincontext->iteration (1) while !${$_[0]};
57}
58
591;
60

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines