Author: spadkins
Date: Tue Sep 18 12:04:11 2007
New Revision: 9950

Modified:
   p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm

Log:
updates to POE::Server.poe_shutdown to more appropriately deal with closing off 
connections and killing child processes

Modified: p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm
==============================================================================
--- p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm        (original)
+++ p5ee/trunk/App-Context/lib/App/Context/POE/Server.pm        Tue Sep 18 
12:04:11 2007
@@ -547,7 +547,7 @@
         $self->{proc} = {};
         $SIG{INT}  = sub { $self->log({level=>2},"Caught Signal: @_ 
(quitting)\n"); $self->exit(102); };   # SIG  2
         $SIG{QUIT} = sub { $self->log({level=>2},"Caught Signal: @_ 
(quitting)\n"); $self->exit(103); };   # SIG  3
-        $SIG{TERM} = sub { $self->log({level=>2},"Caught Signal: @_ 
(quitting)\n"); $self->exit(115); };   # SIG 15
+        $SIG{TERM} = sub { $self->log({level=>2},"Caught Signal: @_ 
(quitting)\n"); $self->shutdown(); $self->exit(115); };   # SIG 15
     }
     &App::sub_exit($pid) if ($App::trace);
     return($pid);
@@ -817,7 +817,9 @@
     # How do I shut down the POE kernel now and exit?
     # I think I need to shut down the last session and the kernel will exit.
     # As per http://poe.perl.org/?POE_FAQ/How_do_I_force_a_session_to_shut_down
-    #     $kernel->yield("poe_shutdown");
+    #     or http://www.mail-archive.com/[EMAIL PROTECTED]/msg03488.html 
+    #$kernel->sig_handled();
+    #$kernel->yield("poe_shutdown");
     # However the signals which bring me here seem to do the shutdown for me, 
so it's unnecessary
 
     &App::sub_exit() if ($App::trace);
@@ -884,23 +886,29 @@
     my ( $self, $kernel, $session, $heap ) = @_[ OBJECT, KERNEL, SESSION, HEAP 
];
     $self->log({level=>2},"POE: poe_shutdown\n") if 
$self->{options}{poe_trace};
 
-    # delete all wheels.
-    delete $heap->{wheel};
+    ### Abort all running async events
+    for my $event_token (keys %{$self->{running_async_event}}) {
+        ### We can't use the normal abort_async_event
+        ### because POE and IKC are shutting down shortly
+        $self->_abort_running_async_event($event_token);
+        $self->log({level=>2},"POE: poe_shutdown : abort running events : 
event_token=[$event_token]\n") if $self->{options}{poe_trace};
+    }
 
-    # clear your alias
-    $kernel->alias_remove( $heap->{alias} );
+    ### Clear your alias
+    $kernel->alias_remove( $self->{poe_session_name} );
 
-    # clear all alarms you might have set
+    ### Clear all alarms you might have set
     $kernel->alarm_remove_all();
 
-    # get rid of external ref count
+    ### Get rid of external ref count
     $kernel->refcount_decrement( $session, $self->{poe_session_name} );
 
+    ### Shut down the HTTP server
     $kernel->post( $self->{poe_kernel_http_name}, 'SHUTDOWN');
+
+    ### Shut down POE IKC
     $kernel->post('IKC', 'shutdown');
 
-    # propagate the message to children
-    $kernel->post( $heap->{child_session}, 'poe_shutdown' );
     &App::sub_exit() if ($App::trace);
     return;
 }

Reply via email to