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.4 by root, Fri Dec 30 01:28:31 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
7my %RWE = (
8 hup => 'rw',
9 in => 'r',
10 out => 'w',
11 pri => 'e',
12);
13 9
14sub io { 10sub io {
15 my ($class, %arg) = @_; 11 my ($class, %arg) = @_;
16 12
17 my $self = bless \%arg, $class; 13 my $self = bless \%arg, $class;
18 my $rcb = \$self->{cb}; 14 my $rcb = \$self->{cb};
19 15
16 my @cond;
20 # some glibs need hup, others error with it, YMMV 17 # some glibs need hup, others error with it, YMMV
21 push @cond, "in", "hup" if $self->{poll} =~ /r/i; 18 push @cond, "in", "hup" if $self->{poll} eq "r";
22 push @cond, "out", "hup" if $self->{poll} =~ /w/i; 19 push @cond, "out", "hup" if $self->{poll} eq "w";
23 push @cond, "pri" if $self->{poll} =~ /e/i;
24 20
25 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub { 21 $self->{source} = add_watch Glib::IO fileno $self->{fh}, \@cond, sub {
26 $$rcb->(join "", map $RWE{$_}, @{ $_[1] }); 22 $$rcb->();
27 ! ! $$rcb 23 ! ! $$rcb
28 }; 24 };
29 25
30 $self 26 $self
31} 27}
42 }; 38 };
43 39
44 $self 40 $self
45} 41}
46 42
47sub cancel { 43sub DESTROY {
48 my ($self) = @_; 44 my ($self) = @_;
49 45
50 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
51 $self->{cb} = undef; 48 $self->{cb} = undef;
52 delete $self->{cb}; 49 %$self = ();
53} 50}
54 51
55sub DESTROY { 52sub one_event {
56 my ($self) = @_; 53 $maincontext->iteration (1);
57
58 $self->cancel;
59} 54}
60
61sub condvar {
62 my $class = shift;
63
64 bless \my $x, AnyEvent::Impl::Glib::CondVar::
65}
66
67sub AnyEvent::Impl::Glib::CondVar::broadcast {
68 ${$_[0]}++;
69}
70
71sub AnyEvent::Impl::Glib::CondVar::wait {
72 $maincontext->iteration (1) while !${$_[0]};
73}
74
75$AnyEvent::MODEL = __PACKAGE__;
76 55
771 561
78 57

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines