AnyEvent-Ping-TCP

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

{
   "abstract" : "Asynchronous and Synchronous TCP ping functions.",
   "author" : [
      "Phillip O'Donnell <podonnell@cpan.org>"
   ],
   "dynamic_config" : 1,
   "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921",
   "license" : [
      "unknown"
   ],
   "meta-spec" : {
      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",

META.yml  view on Meta::CPAN

---
abstract: 'Asynchronous and Synchronous TCP ping functions.'
author:
  - "Phillip O'Donnell <podonnell@cpan.org>"
build_requires:
  ExtUtils::MakeMaker: 0
configure_requires:
  ExtUtils::MakeMaker: 0
dynamic_config: 1
generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.120921'
license: unknown
meta-spec:

README  view on Meta::CPAN

AnyEvent-Ping-TCP version 1.01
==============================

NAME

AnyEvent::Ping::TCP - Asynchronous and Synchronous TCP ping functions.

SYNOPSIS

   use AnyEvent::Ping::TCP;

   # Synchronous TCP Ping
   my $latency = tcp_ping 'www.google.co.nz', 80;

   # Asynchronous TCP Ping
   tcp_ping_syn 'www.google.co.nz', 80;

   # Sometime later
   my $latency = tcp_ping_ack 'www.google.co.nz', 80;

DESCRIPTION

This module provides a very simple implementation of TCP Ping, with both 
an asynchronous and synchronous interface.

Latency is always returned in milliseconds, and is provided by Time::HiRes
Socket functionality is provided by AnyEvent::Socket

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make

lib/AnyEvent/Ping/TCP.pm  view on Meta::CPAN

=head1 NAME

AnyEvent::Ping::TCP - Asynchronous and Synchronous TCP ping functions.

=head1 SYNOPSIS

  use AnyEvent::Ping::TCP;
  
  # Synchronous TCP Ping
  my $latency = tcp_ping 'www.google.co.nz', 80;
  
  # Asynchronous TCP Ping
  tcp_ping_syn 'www.google.co.nz', 80;
  
  # Sometime later
  my $latency = tcp_ping_ack 'www.google.co.nz', 80;
  
=head1 DESCRIPTION

This module provides a very simple implementation of TCP Ping, with both an asynchronous and synchronous interface.

Latency is always returned in milliseconds, and is provided by Time::HiRes

Socket functionality is provided by AnyEvent::Socket

All functions are exported by default.

=cut

package AnyEvent::Ping::TCP;

lib/AnyEvent/Ping/TCP.pm  view on Meta::CPAN

our $VERSION = '1.01';

our %PingQueue = ();

=head2 Synchronous API

=over 4
 
=item $latency = tcp_ping $site, $port [, $timeout]

Measures the time taken to connect to the provided $site:$port and returns it synchronously.

$timeout is optional, and defaults to 5 seconds if not provided.

=back

=cut

sub tcp_ping {
	my $host = shift;
	my $port = shift;
	my $timeout = shift || 5;

	tcp_ping_syn($host, $port, $timeout);
	return tcp_ping_ack($host, $port);
}

=head2 Asynchronous API

=over 4

=item tcp_ping_syn $site, $port [, $timeout]

Initiates the connection to the provided $site:$port and sets a callback to calculate the latency. Correct latency measurement is
not dependant on timely calls to tcp_ping_ack. 

$timeout is optional, and defaults to 5 seconds if not provided.



( run in 0.310 second using v1.01-cache-2.11-cpan-0d8aa00de5b )