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.5 by root, Sun Jan 8 04:20:05 2006 UTC vs.
Revision 1.6 by root, Mon Oct 30 20:52:24 2006 UTC

1package AnyEvent::Impl::Glib; 1package AnyEvent::Impl::Glib;
2 2
3use Glib (); 3use Glib ();
4 4
5my $maincontext = Glib::MainContext->default; 5my $maincontext = Glib::MainContext->default;
6
7my %RWE = (
8 hup => 'rw',
9 in => 'r',
10 out => 'w',
11 pri => 'e',
12);
13 6
14sub io { 7sub io {
15 my ($class, %arg) = @_; 8 my ($class, %arg) = @_;
16 9
17 my $self = bless \%arg, $class; 10 my $self = bless \%arg, $class;
18 my $rcb = \$self->{cb}; 11 my $rcb = \$self->{cb};
19 12
20 # some glibs need hup, others error with it, YMMV 13 # some glibs need hup, others error with it, YMMV
21 push @cond, "in", "hup" if $self->{poll} =~ /r/i; 14 push @cond, "in", "hup" if $self->{poll} eq "r";
22 push @cond, "out", "hup" if $self->{poll} =~ /w/i; 15 push @cond, "out", "hup" if $self->{poll} eq "w";
23 push @cond, "pri" if $self->{poll} =~ /e/i;
24 16
25 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub { 17 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub {
26 $$rcb->(join "", map $RWE{$_}, @{ $_[1] }); 18 $$rcb->();
27 ! ! $$rcb 19 ! ! $$rcb
28 }; 20 };
29 21
30 $self 22 $self
31} 23}
42 }; 34 };
43 35
44 $self 36 $self
45} 37}
46 38
47sub cancel { 39sub DESTROY {
48 my ($self) = @_; 40 my ($self) = @_;
49 41
50 remove Glib::Source delete $self->{source} if $self->{source}; 42 remove Glib::Source delete $self->{source} if $self->{source};
43 # need to undef $cb because we hold references to it
51 $self->{cb} = undef; 44 $self->{cb} = undef;
52 delete $self->{cb}; 45 %$self = ();
53}
54
55sub DESTROY {
56 my ($self) = @_;
57
58 $self->cancel;
59} 46}
60 47
61sub condvar { 48sub condvar {
62 my $class = shift; 49 my $class = shift;
63 50
64 bless \my $x, AnyEvent::Impl::Glib::CondVar:: 51 bless \my $flag, $class
65} 52}
66 53
67sub AnyEvent::Impl::Glib::CondVar::broadcast { 54sub broadcast {
68 ${$_[0]}++; 55 ${$_[0]}++;
69} 56}
70 57
71sub AnyEvent::Impl::Glib::CondVar::wait { 58sub wait {
72 $maincontext->iteration (1) while !${$_[0]}; 59 $maincontext->iteration (1) while !${$_[0]};
73} 60}
74 61
751 621
76 63

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines