File: example.pl

package info (click to toggle)
libanyevent-connection-perl 0.06-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 240 kB
  • sloc: perl: 2,560; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 652 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

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

package My::Client;

use base 'AnyEvent::Connection';

package main;

my $cl = My::Client->new(
	host      => '127.0.0.1',
	port      => 7,
	reconnect => 1,
	debug     => 0,
	timeout   => 1,
);
my $cv = AnyEvent->condvar;
my $fails = 0;
$cl->reg_cb(
	connected => sub {
		my ($cl,$con,$host,$port) = @_;
		warn "Connected $host:$port";
		$cl->disconnect('requested');
	},
	connfail => sub {
		my ($cl,$reason) = @_;
		warn "Connection failed: $reason";
		$fails++>1 and $cl->disconnect('failures');
	},
	disconnect => sub {
		my ($cl,$reason) = @_;
		warn "Disconnected: $reason";
		$cv->send;
	},
);
$cl->connect;
$cv->recv;