… | |
… | |
27 | no warnings; |
27 | no warnings; |
28 | |
28 | |
29 | use AnyEvent; |
29 | use AnyEvent; |
30 | |
30 | |
31 | BEGIN { |
31 | BEGIN { |
32 | our $VERSION = '1.12'; |
32 | our $VERSION = '1.13'; |
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 | |
… | |
… | |
161 | entry for each received packet (replies are being batched for greater |
161 | entry for each received packet (replies are being batched for greater |
162 | efficiency). Each packet is represented by an arrayref with three members: |
162 | efficiency). Each packet is represented by an arrayref with three members: |
163 | the source address (an octet string of either 4 (IPv4) or 16 (IPv6) octets |
163 | the source address (an octet string of either 4 (IPv4) or 16 (IPv6) octets |
164 | length), the payload as passed to C<icmp_ping> and the round trip time in |
164 | length), the payload as passed to C<icmp_ping> and the round trip time in |
165 | seconds. |
165 | seconds. |
|
|
166 | |
|
|
167 | Example: register a callback which simply dumps the received data. Since |
|
|
168 | the coderef is created on the fly via sub, it would be hard to unregister |
|
|
169 | this callback again :) |
|
|
170 | |
|
|
171 | AnyEvent::FastPing::register_cb sub { |
|
|
172 | for (@{$_[0]}) { |
|
|
173 | printf "%s %d %g\n", |
|
|
174 | (4 == length $_->[0] ? inet_ntoa $_->[0] : Socket6::inet_ntop (&AF_INET6, $_->[0])), |
|
|
175 | $_->[2], |
|
|
176 | $_->[1]; |
|
|
177 | } |
|
|
178 | }; |
166 | |
179 | |
167 | Example: a single ping reply with payload of 1 from C<::1> gets passed |
180 | Example: a single ping reply with payload of 1 from C<::1> gets passed |
168 | like this: |
181 | like this: |
169 | |
182 | |
170 | [ [ |
183 | [ [ |
… | |
… | |
196 | |
209 | |
197 | =cut |
210 | =cut |
198 | |
211 | |
199 | our @CB; |
212 | our @CB; |
200 | |
213 | |
201 | sub register_cb(&) { |
214 | sub register_cb($) { |
202 | push @CB, $_[0]; |
215 | push @CB, $_[0]; |
203 | } |
216 | } |
204 | |
217 | |
205 | sub unregister_cb($) { |
218 | sub unregister_cb($) { |
206 | @CB = grep $_ != $_[0], @CB; |
219 | @CB = grep $_ != $_[0], @CB; |