Skip to content

Commit

Permalink
Clean up the client cleanup a little.
Browse files Browse the repository at this point in the history
  • Loading branch information
rcaputo committed Apr 12, 2010
1 parent f1b098d commit 6c37951
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 4 additions & 6 deletions eg/eg-35-tcp-client.pl
Expand Up @@ -10,19 +10,17 @@

after on_my_connected => sub {
my ($self, $args) = @_;
$self->server()->put("Hello, world!\n");
$self->connection()->put("Hello, world!\n");
};

sub on_server_stream {
sub on_connection_stream {
my ($self, $args) = @_;

# Not chomped.
warn "got from server: $args->{data}";

# Close the connection after we've got the echo.
# TODO - Moosey way to clear this?
# TODO - Socket shutdown?
$self->server(undef);
# Disconnect after we receive the echo.
$self->stop();
}
}

Expand Down
20 changes: 11 additions & 9 deletions lib/Reflex/Client.pm
Expand Up @@ -16,7 +16,7 @@ has protocol => (
default => 'Reflex::Stream',
);

has server => (
has connection => (
is => 'rw',
isa => 'Maybe[Reflex::Stream]',
traits => ['Reflex::Trait::Observer'],
Expand All @@ -27,7 +27,7 @@ sub on_my_connected {

$self->stop();

$self->server(
$self->connection(
$self->protocol()->new(
handle => $args->{socket},
rd => 1,
Expand All @@ -38,22 +38,24 @@ sub on_my_connected {
sub on_my_fail {
my ($self, $args) = @_;
warn "$args->{errfun} error $args->{errnum}: $args->{errstr}\n";

$self->stop();
}

sub on_server_close {
sub on_connection_close {
my ($self, $args) = @_;
warn "server closed connection.\n";

$self->sever()->stop();
$self->stop();
}

sub on_server_fail {
sub on_connection_fail {
my ($self, $args) = @_;
warn "$args->{errfun} error $args->{errnum}: $args->{errstr}\n";

$self->server()->stop();
$self->stop();
}

after stop => sub {
my $self = shift;
$self->connection(undef);
};

1;

0 comments on commit 6c37951

Please sign in to comment.