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.3 by root, Fri May 4 12:50:44 2007 UTC vs.
Revision 1.4 by root, Fri May 4 13:50:02 2007 UTC

96 96
97The C<$send_interval> is the minimum interval between sending any two 97The C<$send_interval> is the minimum interval between sending any two
98packets and is a way to make an overall rate limit. If omitted, pings will 98packets and is a way to make an overall rate limit. If omitted, pings will
99be send as fast as possible. 99be send as fast as possible.
100 100
101The C<$payload> is a 32 bit integer given as the ICMP ECHO REQUEST ident 101The C<$payload> is a 32 bit unsigned integer given as the ICMP ECHO
102and sequence numbers (in unspecified order :). 102REQUEST ident and sequence numbers (in unspecified order :).
103 103
104The request will be queued and all requests will be served by a background 104The request will be queued and all requests will be served by a background
105thread in order. When all ranges have been pinged, the C<callback> will be 105thread in order. When all ranges have been pinged, the C<callback> will be
106called. 106called.
107 107
144our $ICMP4_FH; 144our $ICMP4_FH;
145our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4); 145our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4);
146our $ICMP6_FH; 146our $ICMP6_FH;
147our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6); 147our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6);
148 148
149=item Net::FPing::register_cb \&cb
150
151Register a callback that is called for every received ping reply
152(regardless of whether a ping is still in process or not and regardless of
153whether the reply is actually a reply ot a ping sent earlier).
154
155The code reference gets a single parameter - an arrayref with an
156entry for each received packet (replies are beign batched for greater
157efficiency). Each packet is represented by an arrayref with three members:
158the source address (an octet string of either 4 (IPv4) or 16 (IPv6) octets
159length), the payload as passed to C<icmp_ping> and the round trip time in
160seconds.
161
162Example: a single ping reply with payload of 1 from C<::1> gets passed
163like this:
164
165 [ [
166 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1",
167 "0.000280141830444336",
168 1
169 ] ]
170
171Example: ping replies for C<127.0.0.1> and C<127.0.0.2>, with a payload of
172C<0x12345678>:
173
174 [
175 [
176 "\177\0\0\1",
177 "0.00015711784362793",
178 305419896
179 ],
180 [
181 "\177\0\0\2",
182 "0.00090184211731",
183 305419896
184 ]
185 ]
186
187=item Net::FPing::unregister_cb \&cb
188
189Unregister the callback again (make sure you pass the same codereference
190as to C<register_cb>).
191
192=cut
193
194our @CB;
195
196sub register_cb(&) {
197 push @CB, $_[0];
198}
199
200sub unregister_cb($) {
201 @CB = grep $_ != $_[0], @CB;
202}
203
1491; 2041;
150 205
151=back 206=back
152 207
153=head1 BUGS AND SHORTCOMINGS 208=head1 BUGS AND SHORTCOMINGS

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines