AnyEvent-Connection

 view release on metacpan or  search on metacpan

t/01-test.t  view on Meta::CPAN

#!/usr/bin/env perl

use common::sense;
use lib::abs '../lib';

package Echo::Client;

use base 'AnyEvent::Connection';

package main;

use Test::TCP;
use AnyEvent::Impl::Perl;
use AnyEvent;
use AnyEvent::Socket;

use Test::More tests => 22;
use Test::NoWarnings;

diag "Testing AnyEvent::Connection $AnyEvent::Connection::VERSION $INC{'AnyEvent/Connection.pm'}";

my $cv = AnyEvent->condvar;
$SIG{ALRM} = sub { $cv->send; die "Alarm clock"; };
alarm 10;
test_tcp(
	server => sub {
		my $port = shift;
		diag "$$: sr $port";
		my $count;
		my %st;
		$st{server} = tcp_server undef,$port, sub {
			#warn "got conn @_";
			my $h = AnyEvent::Handle->new(
				fh => $_[0],
			);
			$h->on_error(sub{ $h->destroy; undef $h; });
			$h->push_read(line => sub {
				shift;
				if ($_[0] =~ /reset/) {
					diag "Initiating connection reset";
					#$h->push_write("some shit \n");
					$h->destroy;
					undef $h;
					%st = ();
					$st{server} = tcp_server undef,$port, sub {
						#warn "got new conn @_";
					};
				}
			});
		};
		$cv->recv;
	},
	client => sub {
		my $port = shift;
		diag "$$: cl $port";
		my $cl = Echo::Client->new(
			host  => '127.0.0.1',
			port  => $port,
			reconnect => 0.1,
			debug => 0,
		);
		my $action = 0;
		$cl->reg_cb(
			connected => sub {



( run in 0.738 second using v1.01-cache-2.11-cpan-39bf76dae61 )