diff options
author | Yorhel <git@yorhel.nl> | 2012-02-22 11:22:12 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2012-02-22 11:22:12 +0100 |
commit | 6a066068c70336d205dfcd1adc9e0c68ba34ffc0 (patch) | |
tree | d1da405d11a18d54c43bd102af3f5039253c7478 | |
parent | 81fc5992111807e84398e49c91fb45216e99df8e (diff) |
perl: Updated Tanja::Link to use the new protocol
-rw-r--r-- | perl/Tanja.pm | 19 | ||||
-rwxr-xr-x | perl/test.pl | 2 |
2 files changed, 9 insertions, 12 deletions
diff --git a/perl/Tanja.pm b/perl/Tanja.pm index 6dd29ab..ae04aaa 100644 --- a/perl/Tanja.pm +++ b/perl/Tanja.pm @@ -189,7 +189,6 @@ use Carp 'croak'; # Args: Tanja::Server, AnyEvent::Handle, %options # Options: -# init => bool. True if the other party connected to us, false otherwise. (Default false) # sync => bool. True to fetch the other servers' patterns. (Default true) # on_error => $cb->($message). Called when an error occurs, $message = undef for disconnect. # on_ready => $cb->(). Called when the link is "ready". (i.e. if you send tuples they will be forwarded) @@ -200,7 +199,6 @@ sub new { require AnyEvent::Handle; croak 'No JSON module available.' if !Tanja::Link::JSON->init; my $s = bless { - init => 0, sync => 1, %o, serv => $serv, @@ -252,21 +250,20 @@ sub _write { sub _handshake { my $s = shift; - # If we should initiate the handshake, do so - $s->{init} && $s->{hdl}->push_write("ver,1.0 ser,json\012"); + # Send our handshake message + $s->{hdl}->push_write("ver,1.0 seri,json sero,json\012"); # Receive handshake from other party $s->{hdl}->push_read(line => "\012" => sub { my $ver = ($_[1] =~ /\bver,([^ ]+)\b/) && $1; - my $ser = ($_[1] =~ /\bser,([^ ]+)\b/) && $1; + my $seri = ($_[1] =~ /\bseri,([^ ]+)\b/) && $1; + my $sero = ($_[1] =~ /\bsero,([^ ]+)\b/) && $1; # Validate - $s->_err("Invalid handshake: $_[1]") if !$ver || !$ser - || ($s->{init} ? $ver ne '1.0' : !grep /^1\./, split /,/, $ver) - || ($s->{init} ? $ser ne 'json' : !grep $_ eq 'json', split /,/, $ser); - - # Reply with our handshake if we hadn't sent it yet. - !$s->{init} && $s->{hdl}->push_write("ver,1.0 ser,json\012"); + $s->_err("Invalid handshake: $_[1]") if !$ver or !$seri or !$sero + or !grep /^1\./, split /,/, $ver + or !grep $_ eq 'json', split /,/, $seri + or !grep $_ eq 'json', split /,/, $sero; # Handshake complete, start receiving stuff $s->{hdl}->push_read('Tanja::Link::JSON' => sub { $s->_recv(@_) }); diff --git a/perl/test.pl b/perl/test.pl index 3d86748..bed74e0 100755 --- a/perl/test.pl +++ b/perl/test.pl @@ -121,7 +121,7 @@ sub t_double { on_ready => sub { $done->end }, $DEBUG ? (on_write => sub { note 'A: ',Data::Dumper::Dumper(\@_) }) : (), ); - $sb->link(AnyEvent::Handle->new(fh => $sockb), sync => $f&2, init => 1, + $sb->link(AnyEvent::Handle->new(fh => $sockb), sync => $f&2, on_ready => sub { $done->end }, $DEBUG ? (on_write => sub { note 'B: ',Data::Dumper::Dumper(\@_) }) : (), ); |