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.8 by root, Wed Apr 7 14:13:16 2010 UTC vs.
Revision 1.9 by root, Sun Jan 16 11:48:15 2011 UTC

21 21
22=cut 22=cut
23 23
24package AnyEvent::FastPing; 24package AnyEvent::FastPing;
25 25
26use strict; 26use common::sense;
27no warnings;
28 27
29use AnyEvent; 28use AnyEvent;
30 29
31BEGIN { 30BEGIN {
32 our $VERSION = '1.13'; 31 our $VERSION = '1.14';
33 our @ISA = qw(Exporter); 32 our @ISA = qw(Exporter);
34 33
35 require Exporter; 34 require Exporter;
36 #Exporter::export_ok_tags (keys %EXPORT_TAGS); 35 #Exporter::export_ok_tags (keys %EXPORT_TAGS);
37 36
43 42
44our $THR_REQ_FH; open $THR_REQ_FH, ">&=$THR_REQ_FD" or die "FATAL: cannot fdopen"; 43our $THR_REQ_FH; open $THR_REQ_FH, ">&=$THR_REQ_FD" or die "FATAL: cannot fdopen";
45our $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";
46 45
47our $THR_REQ_W; 46our $THR_REQ_W;
48our $THR_RES_W = AnyEvent->io (fh => $THR_RES_FH, poll => 'r', cb => sub { 47our $THR_RES_W = AE::io $THR_RES_FH, 0, sub {
49 my $sv = _read_res 48 my $sv = _read_res
50 or return; 49 or return;
51 50
52 $sv->(); 51 $sv->();
53}); 52};
54 53
55our $THR_REQ_BUF; 54our $THR_REQ_BUF;
56 55
57sub _send_req($) { 56sub _send_req($) {
58 $THR_REQ_BUF .= $_[0]; 57 $THR_REQ_BUF .= $_[0];
59 58
60 $THR_REQ_W ||= AnyEvent->io (fh => $THR_REQ_FH, poll => 'w', cb => sub { 59 $THR_REQ_W ||= AE::io $THR_REQ_FH, 1, sub {
61 my $len = syswrite $THR_REQ_FH, $THR_REQ_BUF; 60 my $len = syswrite $THR_REQ_FH, $THR_REQ_BUF;
62 substr $THR_REQ_BUF, 0, $len, ""; 61 substr $THR_REQ_BUF, 0, $len, "";
63 62
64 undef $THR_REQ_W unless length $THR_REQ_BUF; 63 undef $THR_REQ_W unless length $THR_REQ_BUF;
65 }); 64 };
66} 65}
67 66
68=item AnyEvent::FastPing::ipv4_supported 67=item AnyEvent::FastPing::ipv4_supported
69 68
70Returns true if IPv4 is supported in this module and on this system. 69Returns true if IPv4 is supported in this module and on this system.
145sub icmp_ping($$$&) { 144sub icmp_ping($$$&) {
146 _send_req _req_icmp_ping @_; 145 _send_req _req_icmp_ping @_;
147} 146}
148 147
149our $ICMP4_FH; 148our $ICMP4_FH;
150our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AnyEvent->io (fh => $ICMP4_FH, poll => 'r', cb => \&_recv_icmp4); 149our $ICMP4_W = (open $ICMP4_FH, "<&=$ICMP4_FD") && AE::io $ICMP4_FH, 0, \&_recv_icmp4;
151our $ICMP6_FH; 150our $ICMP6_FH;
152our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AnyEvent->io (fh => $ICMP6_FH, poll => 'r', cb => \&_recv_icmp6); 151our $ICMP6_W = (open $ICMP6_FH, "<&=$ICMP6_FD") && AE::io $ICMP6_FH, 0, \&_recv_icmp6;
153 152
154=item AnyEvent::FastPing::register_cb \&cb 153=item AnyEvent::FastPing::register_cb \&cb
155 154
156Register a callback that is called for every received ping reply 155Register a callback that is called for every received ping reply
157(regardless of whether a ping is still in process or not and regardless of 156(regardless of whether a ping is still in process or not and regardless of

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines