better cleanup
Matt S Trout [Tue, 29 Nov 2011 21:33:50 +0000 (21:33 +0000)]
lib/Tak/Daemon/ListenerService.pm

index 3ef2a8b..f9738ce 100644 (file)
@@ -55,6 +55,9 @@ sub _build__start_in_progress {
       on_accept => sub {
         $self->setup_connection($_[0]);
       },
+      on_accept_error => sub {
+        $self->handle_stop;
+      },
     );
     $start{start} = sub {}; # delete yourself
   };
@@ -67,6 +70,7 @@ sub handle_stop {
   # there's probably something more intelligent to do here, but meh
   die failure => 'starting' if $self->state eq 'starting';
   Tak->loop->remove($self->clear_listener);
+  unlink($self->socket_location);
   $self->state('down');
   return 'stopped';
 }
@@ -76,6 +80,7 @@ sub DEMOLISH {
   return if $gd;
   if (my $l = $self->listener) {
     $l->get_loop->remove($l);
+    unlink($self->socket_location);
   }
 }
 
@@ -85,7 +90,7 @@ sub setup_connection {
   my $connection;
   $connection = Tak::ConnectionService->new(
     read_fh => $socket, write_fh => $socket,
-    listening_service => $self->router,
+    listening_service => $self->router->clone,
     on_close => sub { delete $conn_set->{$connection} }
   );
   $conn_set->{$connection} = $connection;