ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-FastPing/FastPing.pm
(Generate patch)

Comparing AnyEvent-FastPing/FastPing.pm (file contents):
Revision 1.14 by root, Wed Feb 2 20:04:17 2011 UTC vs.
Revision 1.18 by root, Fri Nov 11 01:18:56 2016 UTC

27use common::sense; 27use common::sense;
28 28
29use AnyEvent; 29use AnyEvent;
30 30
31BEGIN { 31BEGIN {
32 our $VERSION = '2.0'; 32 our $VERSION = 2.03;
33 our @ISA = qw(Exporter); 33 our @ISA = qw(Exporter);
34 34
35 require Exporter; 35 require Exporter;
36 #Exporter::export_ok_tags (keys %EXPORT_TAGS); 36 #Exporter::export_ok_tags (keys %EXPORT_TAGS);
37 37
41 41
42our ($THR_RES_FD, $ICMP4_FD, $ICMP6_FD); 42our ($THR_RES_FD, $ICMP4_FD, $ICMP6_FD);
43 43
44our $THR_RES_FH; open $THR_RES_FH, "<&=$THR_RES_FD" or die "FATAL: cannot fdopen"; 44our $THR_RES_FH; open $THR_RES_FH, "<&=$THR_RES_FD" or die "FATAL: cannot fdopen";
45 45
46our $ICMP4_FH;
47our $ICMP6_FH;
48
49our @IDLE_CB;
50
51AnyEvent::post_detect {
46our $ICMP4_FH; our $ICMP4_W = $ICMP4_FD >= 0 && (open $ICMP4_FH, "<&=$ICMP4_FD") && AE::io $ICMP4_FH, 0, \&_recv_icmp4; 52 our $ICMP4_W = $ICMP4_FD >= 0 && (open $ICMP4_FH, "<&=$ICMP4_FD") && AE::io $ICMP4_FH, 0, \&_recv_icmp4;
47our $ICMP6_FH; our $ICMP6_W = $ICMP6_FD >= 0 && (open $ICMP6_FH, "<&=$ICMP6_FD") && AE::io $ICMP6_FH, 0, \&_recv_icmp6; 53 our $ICMP6_W = $ICMP6_FD >= 0 && (open $ICMP6_FH, "<&=$ICMP6_FD") && AE::io $ICMP6_FH, 0, \&_recv_icmp6;
54
55 our $THR_RES_W = AE::io $THR_RES_FH, 0, sub {
56 sysread $THR_RES_FH, my $buf, 8;
57
58 for my $id (unpack "S*", $buf) {
59 _stop_id $id;
60 ($IDLE_CB[$id] || sub { })->();
61 }
62 };
63};
48 64
49=item AnyEvent::FastPing::ipv4_supported 65=item AnyEvent::FastPing::ipv4_supported
50 66
51Returns true iff IPv4 is supported in this module and on this system. 67Returns true iff IPv4 is supported in this module and on this system.
52 68
153=cut 169=cut
154 170
155sub new { 171sub new {
156 my ($klass) = @_; 172 my ($klass) = @_;
157 173
174 AnyEvent::detect unless defined $AnyEvent::MODEL;
175
158 _new $klass, (rand 65536), (rand 65536), (rand 65536) 176 _new $klass, (rand 65536), (rand 65536), (rand 65536)
159} 177}
160
161our @IDLE_CB;
162 178
163sub DESTROY { 179sub DESTROY {
164 undef $IDLE_CB[ &id ]; 180 undef $IDLE_CB[ &id ];
165 &_free; 181 &_free;
166} 182}
226 242
227sub on_idle { 243sub on_idle {
228 $IDLE_CB[ &id ] = $_[1]; 244 $IDLE_CB[ &id ] = $_[1];
229} 245}
230 246
231our $THR_RES_W = AE::io $THR_RES_FH, 0, sub {
232 sysread $THR_RES_FH, my $buf, 8;
233
234 for my $id (unpack "S*", $buf) {
235 _stop_id $id;
236 ($IDLE_CB[$id] || sub { })->();
237 }
238};
239
240=item $pinger->interval ($seconds) 247=item $pinger->interval ($seconds)
241 248
242Configures the minimum interval between packet sends for this pinger - the 249Configures the minimum interval between packet sends for this pinger - the
243pinger will not send packets faster than this rate (or actually 1 / rate), 250pinger will not send packets faster than this rate (or actually 1 / rate),
244even if individual ranges have a lower interval. 251even if individual ranges have a lower interval.
284 291
285=item $pinger->add_hosts ([$host...], $interval, $interleave) 292=item $pinger->add_hosts ([$host...], $interval, $interleave)
286 293
287Similar to C<add_range>, but uses a list of single addresses instead. The 294Similar to C<add_range>, but uses a list of single addresses instead. The
288list is specified as an array reference as first argument. Each entry in 295list is specified as an array reference as first argument. Each entry in
289the array should be a binary host address, either IPv4 or IPv6. Currently, 296the array should be a binary host address, either IPv4 or IPv6. If all
290all entries in the list must be either IPv4 B<OR> IPv6, so you have to 297addresses are IPv4 addresses, then a compact IPv4-only format will be used
291create two host ranges if you have mixed addresses. 298to store the list internally.
292 299
293Minimum C<$interval> is the same as for C<add_range> and can be left out. 300Minimum C<$interval> is the same as for C<add_range> and can be left out.
294 301
295C<$interlave> specifies an increment between addresses: often address 302C<$interlave> specifies an increment between addresses: often address
296lists are generated in a way that results in clustering - first all 303lists are generated in a way that results in clustering - first all

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines