sub setup_connection {
my ($self, $socket) = @_;
my $conn_set = $self->connections;
- my $connection;
- $connection = Tak::ConnectionService->new(
+ my $conn_str;
+ my $connection = Tak::ConnectionService->new(
read_fh => $socket, write_fh => $socket,
- listening_service => $self->router->clone,
- on_close => sub { delete $conn_set->{$connection} }
+ listening_service => $self->router->clone_or_self,
+ on_close => sub { delete $conn_set->{$conn_str} }
);
- $conn_set->{$connection} = $connection;
+ $conn_str = "$connection";
+ $connection->receiver->service->service->register_weak(remote => $connection);
+ $conn_set->{$conn_str} = $connection;
return;
}