… | |
… | |
39 | our $maincontext = Glib::MainContext->default; |
39 | our $maincontext = Glib::MainContext->default; |
40 | |
40 | |
41 | sub io { |
41 | sub io { |
42 | my ($class, %arg) = @_; |
42 | my ($class, %arg) = @_; |
43 | |
43 | |
44 | my $fh = $arg{fh}; |
|
|
45 | my $cb = $arg{cb}; |
44 | my $cb = $arg{cb}; |
46 | |
45 | |
47 | my @cond; |
46 | my @cond; |
48 | # some glibs need hup, others error with it, YMMV |
47 | # some glibs need hup, others error with it, YMMV |
49 | push @cond, "in", "hup" if $arg{poll} eq "r"; |
48 | push @cond, "in", "hup" if $arg{poll} eq "r"; |
50 | push @cond, "out", "hup" if $arg{poll} eq "w"; |
49 | push @cond, "out", "hup" if $arg{poll} eq "w"; |
51 | |
50 | |
52 | my $source = add_watch Glib::IO fileno $arg{fh}, \@cond, sub { |
51 | my $source = add_watch Glib::IO fileno $arg{fh}, \@cond, sub { |
53 | &$cb; |
52 | &$cb; |
54 | $fh; # mention it here to keep it from being destroyed |
|
|
55 | 1 |
53 | 1 |
56 | }; |
54 | }; |
57 | |
55 | |
58 | bless \\$source, $class |
56 | bless \\$source, $class |
59 | } |
57 | } |