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

Comparing AnyEvent-FastPing/FPing.pm (file contents):
Revision 1.2 by root, Fri May 4 07:36:45 2007 UTC vs.
Revision 1.3 by root, Fri May 4 12:50:44 2007 UTC

16you have to run an event model supported by AnyEvent to use this module. 16you have to run an event model supported by AnyEvent to use this module.
17 17
18Receiving and processing reply packets is not currently supported by this 18Receiving and processing reply packets is not currently supported by this
19module. 19module.
20 20
21=head1 FUNCTIONS
22
21=over 4 23=over 4
22 24
23=cut 25=cut
24 26
25package Net::FPing; 27package Net::FPing;
26 28
29use strict;
30no warnings;
31
27use AnyEvent; 32use AnyEvent;
28 33
29BEGIN { 34BEGIN {
30 $VERSION = '0.01'; 35 our $VERSION = '0.01';
31 @ISA = qw(Exporter); 36 our @ISA = qw(Exporter);
32 37
33 require Exporter; 38 require Exporter;
34 Exporter::export_ok_tags(keys %EXPORT_TAGS); 39 #Exporter::export_ok_tags (keys %EXPORT_TAGS);
35 40
36 require XSLoader; 41 require XSLoader;
37 XSLoader::load __PACKAGE__, $VERSION; 42 XSLoader::load (__PACKAGE__, $VERSION);
38} 43}
44
45our ($THR_REQ_FD, $THR_RES_FD, $ICMP4_FD, $ICMP6_FD);
39 46
40our $THR_REQ_FH; open $THR_REQ_FH, ">&=$THR_REQ_FD" or die "FATAL: cannot fdopen"; 47our $THR_REQ_FH; open $THR_REQ_FH, ">&=$THR_REQ_FD" or die "FATAL: cannot fdopen";
41our $THR_RES_FH; open $THR_RES_FH, "<&=$THR_RES_FD" or die "FATAL: cannot fdopen"; 48our $THR_RES_FH; open $THR_RES_FH, "<&=$THR_RES_FD" or die "FATAL: cannot fdopen";
42 49
43our $THR_REQ_W; 50our $THR_REQ_W;
46 or return; 53 or return;
47 54
48 $sv->(); 55 $sv->();
49}); 56});
50 57
51our @THR_REQ_BUF; 58our $THR_REQ_BUF;
52 59
53sub _send_req($) { 60sub _send_req($) {
54 $THR_REQ_BUF .= $_[0]; 61 $THR_REQ_BUF .= $_[0];
55 62
56 $THR_REQ_W ||= AnyEvent->io (fh => $THR_REQ_FH, poll => 'w', cb => sub { 63 $THR_REQ_W ||= AnyEvent->io (fh => $THR_REQ_FH, poll => 'w', cb => sub {
104time. It will at most send one packet every C<$send_interval> seconds. The 111time. It will at most send one packet every C<$send_interval> seconds. The
105algorithm to send each packet is O(log n) on the number of ranges, so even 112algorithm to send each packet is O(log n) on the number of ranges, so even
106a large number of ranges (many thousands) is managable. No storage is 113a large number of ranges (many thousands) is managable. No storage is
107allocated per address. 114allocated per address.
108 115
109Performance: On my 2 GHZ Opteron system with a pretty average nvidia 116Performance: On my 2 GHz Opteron system with a pretty average nvidia
110gigabit network card I can ping around 60k to 200k adresses per second, 117gigabit network card I can ping around 60k to 200k adresses per second,
111depending on routing decisions. 118depending on routing decisions.
112 119
113Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and 120Example: ping 10.0.0.1-10.0.0.15 with at most 100 packets/s, and
11411.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed 12111.0.0.1-11.0.255.255 with at most 1000 packets/s. Do not, however, exceed
1151000 packets/s overall: 1221000 packets/s overall:
116 123
124 my $done = AnyEvent->condvar;
125
117 Net::FPing::icmp_ping 126 Net::FPing::icmp_ping
118 [v10.0.0.1, v10.0.0.15, .01], 127 [v10.0.0.1, v10.0.0.15, .01],
119 [v11.0.0.1, v11.0.255.255, .001], 128 [v11.0.0.1, v11.0.255.255, .001],
120 .001, 0x12345678, 129 .001, 0x12345678,
121 sub { 130 sub {
122 warn "all ranges pinged\n"; 131 warn "all ranges pinged\n";
132 $done->broadcast;
123 } 133 }
124 ; 134 ;
135
136 $done->wait;
125 137
126=cut 138=cut
127 139
128sub icmp_ping($$$&) { 140sub icmp_ping($$$&) {
129 _send_req _req_icmp_ping @_; 141 _send_req _req_icmp_ping @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines