summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2012-02-23 09:48:31 +0100
committerYorhel <git@yorhel.nl>2012-02-23 09:48:31 +0100
commit9167da8e7ed487240fdfd5d1791b0cdc3a8f6dab (patch)
treeb2e105964b5adfe1145be0313e2c60a4e0f4fe81
parent94d20223d2e4fd9d87913ab2288793cf6de1331a (diff)
s/server/node/g
I find "node" to be much more descriptive for that. The Go implementation hasn't been updated yet, though...
-rw-r--r--Tanja.pm58
-rwxr-xr-xtest.pl20
2 files changed, 39 insertions, 39 deletions
diff --git a/Tanja.pm b/Tanja.pm
index fa68c06..92e2b82 100644
--- a/Tanja.pm
+++ b/Tanja.pm
@@ -23,13 +23,13 @@ sub match {
}
-package Tanja::Server;
+package Tanja::Node;
use strict;
use warnings;
-# Create a new server (representing a "network")
+# Create a new Node
sub new {
return bless({
lastid => 1,
@@ -45,7 +45,7 @@ sub session {
}
-# Link with another server via an AnyEvent::Handle stream
+# Link with a remote node via an AnyEvent::Handle stream
sub link {
return Tanja::Link->new(@_);
}
@@ -53,7 +53,7 @@ sub link {
# Send a tuple to the network.
# Arguments: [ tuple ], $return_cb->([tuple] or undef, $special_arg), $special_arg
-# $special_arg is local only within the server, it will not be routed.
+# $special_arg is local only within the node, it will not be routed.
# TODO: Some way to indicate that the session isn't interested in replies anymore?
sub send {
my($s, $t, $cb, $sa) = @_;
@@ -92,11 +92,11 @@ use strict;
use warnings;
-# Create a new session (usually called by $serv->session)
+# Create a new session (usually called by $node->session)
sub new {
- my($own, $serv) = @_;
+ my($own, $node) = @_;
return bless({
- server => $serv,
+ node => $node,
pat => {},
}, $own);
}
@@ -110,7 +110,7 @@ sub new {
sub reg {
my($s, $pat, $cb) = @_;
my $id;
- $id = $s->{server}->_register($pat, sub { $s->{pat}{$id} && $cb->(@_) });
+ $id = $s->{node}->_register($pat, sub { $s->{pat}{$id} && $cb->(@_) });
$s->{pat}{$id} = 1;
return $id;
}
@@ -119,7 +119,7 @@ sub reg {
# Unregister a single pattern
sub unreg {
my($s, $id) = @_;
- $s->{server}->_unregister($id);
+ $s->{node}->_unregister($id);
delete $s->{pat}{$id};
}
@@ -135,14 +135,14 @@ sub reg_once {
sub send {
my $s = shift;
- $s->{server}->send(@_);
+ $s->{node}->send(@_);
}
# "Close" the session (simply unregisters all its patterns)
sub close {
my $s = shift;
- $s->{server}->_unregister($_) for (keys %{$s->{pat}});
+ $s->{node}->_unregister($_) for (keys %{$s->{pat}});
$s->{pat} = {};
}
@@ -187,9 +187,9 @@ use Errno 'EPIPE';
use Carp 'croak';
-# Args: Tanja::Server, %options
+# Args: Tanja::Node, %options
# Options:
-# sync => bool. True to fetch the other servers' patterns. (Default true)
+# sync => bool. True to fetch the pattern list of the remote node. (Default true)
# handle => AnyEvent::Handle. Equivalent to setting write_handle and read_handle to the same thing.
# write_handle => AnyEvent::Handle. Used for writing.
# read_handle => AnyEvent::Handle. Used for reading.
@@ -199,7 +199,7 @@ use Carp 'croak';
# on_read => $cb->(message => args). Called when a (non-handshake) message has been received.
# formats => [ name => 'module', ... ],
sub new {
- my($own, $serv, %o) = @_;
+ my($own, $node, %o) = @_;
require AnyEvent::Handle;
my $s = bless {
sync => 1,
@@ -207,7 +207,7 @@ sub new {
json => 'Tanja::Link::JSON',
],
%o,
- serv => $serv,
+ node => $node,
reg => {},
ret => {},
lastret => 1,
@@ -246,9 +246,9 @@ sub new {
sub _cleanup {
my $s = shift;
- $s->{serv}->_unregister($_) for (values %{$s->{pat}});
+ $s->{node}->_unregister($_) for (values %{$s->{pat}});
$s->{pat} = {};
- delete $s->{serv}{lnk}{$s};
+ delete $s->{node}{lnk}{$s};
}
sub _err {
@@ -312,7 +312,7 @@ sub _handshake {
if($s->{sync}) {
$s->_write(patternsync => 1);
} else {
- $s->{pat}{_} = $s->{serv}->_register([], $s->{tup});
+ $s->{pat}{_} = $s->{node}->_register([], $s->{tup});
$s->{on_ready} && $s->{on_ready}->();
delete $s->{on_ready};
}
@@ -320,7 +320,7 @@ sub _handshake {
}
-# Generates the subroutine used for registering patterns with the server.
+# Generates the subroutine used for registering patterns with the local node.
sub _tuple {
my $s = shift;
sub { # tuple, ret, sa
@@ -329,7 +329,7 @@ sub _tuple {
return if $_[2] && ref($_[2]) eq 'Tanja::Link' && $_[2] == $s;
# Only send a tuple once even if there have been multiple
- # registrations. (This relies on the property that the Server does not
+ # registrations. (This relies on the property that the Node does not
# make a copy of the tuple when dispatching the callbacks.)
return if $_[0] == $s->{lasttup};
$s->{lasttup} = $_[0];
@@ -347,14 +347,14 @@ sub _tuple {
}
-# Someone registered a pattern with the server
+# Someone registered a pattern with the local node
sub _srv_reg {
my($s, $id, $pat, $cb) = @_;
$cb != $s->{tup} && $s->_write(register => $id+0, $pat);
}
-# Someone unregistered a pattern with the server
+# Someone unregistered a pattern with the local node
sub _srv_unreg {
my($s, $id) = @_;
# Note that this also sends out unregister messages for patterns that the
@@ -374,17 +374,17 @@ sub _recv {
# patternsync
if($cmd eq 'patternsync') {
if($arg[0]) {
- $s->{serv}{lnk}{$s} = $s;
- $s->{serv}{pat}{$_}[1] != $s->{tup} && $s->_write(register => $_+0, $s->{serv}{pat}{$_}[0])
- for (keys %{$s->{serv}{pat}});
+ $s->{node}{lnk}{$s} = $s;
+ $s->{node}{pat}{$_}[1] != $s->{tup} && $s->_write(register => $_+0, $s->{node}{pat}{$_}[0])
+ for (keys %{$s->{node}{pat}});
$s->_write('regdone');
} else {
- delete $s->{serv}{lnk}{$s};
+ delete $s->{node}{lnk}{$s};
}
# register
} elsif($cmd eq 'register') {
- $s->{pat}{$arg[0]} = $s->{serv}->_register($arg[1], $s->{tup}) if $s->{sync};
+ $s->{pat}{$arg[0]} = $s->{node}->_register($arg[1], $s->{tup}) if $s->{sync};
# regdone
} elsif($cmd eq 'regdone') {
@@ -394,13 +394,13 @@ sub _recv {
# unregister
} elsif($cmd eq 'unregister') {
if($s->{sync}) {
- $s->{serv}->_unregister($s->{pat}{$arg[0]});
+ $s->{node}->_unregister($s->{pat}{$arg[0]});
delete $s->{pat}{$arg[0]};
}
# tuple
} elsif($cmd eq 'tuple') {
- $s->{serv}->send($arg[1], !$arg[0] ? undef : sub {
+ $s->{node}->send($arg[1], !$arg[0] ? undef : sub {
$s->_write($_[0]?'reply':'close', $arg[0]+0, $_[0]?$_[0]:());
}, $s);
diff --git a/test.pl b/test.pl
index 25470b2..b0f6272 100755
--- a/test.pl
+++ b/test.pl
@@ -33,9 +33,9 @@ ok !Tanja::match([2], [1]);
# Simple single-session test
{
- my $serv = Tanja::Server->new;
- isa_ok $serv, 'Tanja::Server';
- my $ses = $serv->session;
+ my $node = Tanja::Node->new;
+ isa_ok $node, 'Tanja::Node';
+ my $ses = $node->session;
isa_ok $ses, 'Tanja::Session';
my $done = AnyEvent->condvar;
my $n = 0;
@@ -101,17 +101,17 @@ sub t_double {
is $n, 2;
}
-{ # same server
- my $s = Tanja::Server->new;
- note 'Same server';
+{ # same node
+ my $s = Tanja::Node->new;
+ note 'Same Node';
t_double($s, $s);
}
-{ # different servers, linked. (With various combinations of the 'sync' flag)
+{ # different nodes, linked. (With various combinations of the 'sync' flag)
for my $f (0..3) {
- note "Linked servers, $f";
- my $sa = Tanja::Server->new;
- my $sb = Tanja::Server->new;
+ note "Linked nodes, $f";
+ my $sa = Tanja::Node->new;
+ my $sb = Tanja::Node->new;
t_double($sa, $sb, sub {
socketpair my $socka, my $sockb, AF_UNIX, SOCK_STREAM, PF_UNSPEC;
my $done = AnyEvent->condvar;