| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package IO::AsyncX::EventFD 0.001; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Linux eventfd support for IO::Async |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
57788
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
25
|
|
|
5
|
1
|
|
|
1
|
|
2
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
372
|
use parent qw(IO::Async::Notifier); |
|
|
1
|
|
|
|
|
226
|
|
|
|
1
|
|
|
|
|
3
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
IO::AsyncX::EventFD - simple eventfd notifications |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#!/usr/bin/env perl |
|
16
|
|
|
|
|
|
|
use strict; |
|
17
|
|
|
|
|
|
|
use warnings; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use IO::Async::Loop; |
|
20
|
|
|
|
|
|
|
use IO::AsyncX::EventFD; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $loop = IO::Async::Loop->new; |
|
23
|
|
|
|
|
|
|
$loop->add(my $eventfd = IO::AsyncX::EventFD->new(notify => sub { |
|
24
|
|
|
|
|
|
|
warn "Had event\n" |
|
25
|
|
|
|
|
|
|
})); |
|
26
|
|
|
|
|
|
|
$loop->loop_once(0.001); |
|
27
|
|
|
|
|
|
|
warn "Notifying...\n"; |
|
28
|
|
|
|
|
|
|
$eventfd->notify; |
|
29
|
|
|
|
|
|
|
$loop->loop_once(0.001); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Provides a very thin layer over L. |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
11295
|
use IO::Async::Handle; |
|
|
1
|
|
|
|
|
3943
|
|
|
|
1
|
|
|
|
|
37
|
|
|
38
|
1
|
|
|
1
|
|
476
|
use Linux::FD; |
|
|
1
|
|
|
|
|
8594
|
|
|
|
1
|
|
|
|
|
5
|
|
|
39
|
1
|
|
|
1
|
|
457
|
use curry::weak; |
|
|
1
|
|
|
|
|
575
|
|
|
|
1
|
|
|
|
|
21
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
362
|
use mro; |
|
|
1
|
|
|
|
|
501
|
|
|
|
1
|
|
|
|
|
4
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 METHODS |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 notify |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Sends a notification to the event FD. This consists of a call to |
|
48
|
|
|
|
|
|
|
L with the value 1. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub notify { |
|
53
|
1
|
|
|
1
|
1
|
2412
|
my ($self) = @_; |
|
54
|
1
|
|
|
|
|
4
|
$self->handle->read_handle->add(1); |
|
55
|
1
|
|
|
|
|
10
|
$self |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 eventfd |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns the L handle. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
1
|
0
|
sub eventfd { shift->handle->read_handle } |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 configure |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Configuration. Currently supports the following named parameters: |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over 4 |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item * notify - the callback which will be triggered when there's a new semaphore value |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=back |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub configure { |
|
79
|
1
|
|
|
1
|
1
|
4210
|
my ($self, %args) = @_; |
|
80
|
1
|
|
|
|
|
5
|
for(qw(notify)) { |
|
81
|
1
|
50
|
|
|
|
12
|
$self->{$_} = delete $args{$_} if exists $args{$_}; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
1
|
|
|
|
|
10
|
$self->next::method(%args); |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 METHODS - Internal |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=cut |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 _add_to_loop |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Called when we are added to the loop. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _add_to_loop { |
|
97
|
1
|
|
|
1
|
|
547
|
my ($self, $loop) = @_; |
|
98
|
1
|
|
|
|
|
44
|
my $fd = Linux::FD::Event->new(0, qw(non-blocking semaphore)); |
|
99
|
|
|
|
|
|
|
$self->add_child( |
|
100
|
1
|
|
|
|
|
12
|
$self->{handle} = IO::Async::Handle->new( |
|
101
|
|
|
|
|
|
|
read_handle => $fd, |
|
102
|
|
|
|
|
|
|
on_read_ready => $self->curry::weak::on_read_ready, |
|
103
|
|
|
|
|
|
|
) |
|
104
|
|
|
|
|
|
|
); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 on_read_ready |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Called when there's a read event. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub on_read_ready { |
|
114
|
1
|
|
|
1
|
1
|
673
|
my ($self) = @_; |
|
115
|
1
|
50
|
|
|
|
3
|
return unless my $h = $self->handle->read_handle; |
|
116
|
1
|
|
66
|
|
|
27
|
$self->{notify}->() while $h->get and $self->{notify}; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 handle |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns the underlying L instance. |
|
122
|
|
|
|
|
|
|
=cut |
|
123
|
|
|
|
|
|
|
|
|
124
|
2
|
|
|
2
|
1
|
10
|
sub handle { shift->{handle} } |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |