cleanup connection setup
Matt S Trout [Thu, 1 Dec 2011 22:54:09 +0000 (22:54 +0000)]
lib/Tak/Daemon/ListenerService.pm

index f9738ce..95c0499 100644 (file)
@@ -87,13 +87,15 @@ sub DEMOLISH {
 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;
 }