home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / PerlSignals.pm < prev    next >
Encoding:
Perl POD Document  |  2003-11-21  |  3.4 KB  |  132 lines

  1. # $Id: PerlSignals.pm,v 1.4 2003/11/21 05:08:26 rcaputo Exp $
  2.  
  3. # Plain Perl signal handling is something shared by several event
  4. # loops.  The invariant code has moved out here so that each loop may
  5. # use it without reinventing it.  This will save maintenance and
  6. # shrink the distribution.  Yay!
  7.  
  8. package POE::Loop::PerlSignals;
  9.  
  10. use strict;
  11.  
  12. use vars qw($VERSION);
  13. $VERSION = do {my@r=(q$Revision: 1.4 $=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};
  14.  
  15. # Everything plugs into POE::Kernel.
  16. package POE::Kernel;
  17.  
  18. use strict;
  19. use POE::Kernel;
  20.  
  21. #------------------------------------------------------------------------------
  22. # Signal handlers/callbacks.
  23.  
  24. sub _loop_signal_handler_generic {
  25.   if (TRACE_SIGNALS) {
  26.     POE::Kernel::_warn "<sg> Enqueuing generic SIG$_[0] event";
  27.   }
  28.  
  29.   $poe_kernel->_data_ev_enqueue
  30.     ( $poe_kernel, $poe_kernel, EN_SIGNAL, ET_SIGNAL, [ $_[0] ],
  31.       __FILE__, __LINE__, time()
  32.     );
  33.   $SIG{$_[0]} = \&_loop_signal_handler_generic;
  34. }
  35.  
  36. sub _loop_signal_handler_pipe {
  37.   if (TRACE_SIGNALS) {
  38.     POE::Kernel::_warn "<sg> Enqueuing PIPE-like SIG$_[0] event";
  39.   }
  40.  
  41.   $poe_kernel->_data_ev_enqueue
  42.     ( $poe_kernel, $poe_kernel, EN_SIGNAL, ET_SIGNAL, [ $_[0] ],
  43.       __FILE__, __LINE__, time()
  44.     );
  45.     $SIG{$_[0]} = \&_loop_signal_handler_pipe;
  46. }
  47.  
  48. # Special handler.  Stop watching for children; instead, start a loop
  49. # that polls for them.
  50. sub _loop_signal_handler_child {
  51.   if (TRACE_SIGNALS) {
  52.     POE::Kernel::_warn "<sg> Enqueuing CHLD-like SIG$_[0] event";
  53.   }
  54.  
  55.   $SIG{$_[0]} = 'DEFAULT';
  56.   $poe_kernel->_data_ev_enqueue
  57.     ( $poe_kernel, $poe_kernel, EN_SCPOLL, ET_SCPOLL, [ ],
  58.       __FILE__, __LINE__, time()
  59.     );
  60. }
  61.  
  62. #------------------------------------------------------------------------------
  63. # Signal handler maintenance functions.
  64.  
  65. sub loop_watch_signal {
  66.   my ($self, $signal) = @_;
  67.  
  68.   # Child process has stopped.
  69.   if ($signal eq 'CHLD' or $signal eq 'CLD') {
  70.  
  71.     # Begin constant polling loop.  Only start it on CHLD or on CLD if
  72.     # CHLD doesn't exist.
  73.     $SIG{$signal} = 'DEFAULT';
  74.     $self->_data_ev_enqueue
  75.       ( $self, $self, EN_SCPOLL, ET_SCPOLL, [ ],
  76.         __FILE__, __LINE__, time() + 1
  77.       ) if $signal eq 'CHLD' or not exists $SIG{CHLD};
  78.  
  79.     return;
  80.   }
  81.  
  82.   # Broken pipe.
  83.   if ($signal eq 'PIPE') {
  84.     $SIG{$signal} = \&_loop_signal_handler_pipe;
  85.     return;
  86.   }
  87.  
  88.   # Artur Bergman (sky) noticed that xterm resizing can generate a LOT
  89.   # of WINCH signals.  That rapidly crashes perl, which, with the help
  90.   # of most libc's, can't handle signals well at all.  We ignore
  91.   # WINCH, therefore.
  92.   return if $signal eq 'WINCH';
  93.  
  94.   # Everything else.
  95.   $SIG{$signal} = \&_loop_signal_handler_generic;
  96. }
  97.  
  98. sub loop_ignore_signal {
  99.   my ($self, $signal) = @_;
  100.   $SIG{$signal} = "DEFAULT";
  101. }
  102.  
  103. 1;
  104.  
  105. __END__
  106.  
  107. =head1 NAME
  108.  
  109. POE::Loop::PerlSignals - plain Perl signal handlers used by many loops
  110.  
  111. =head1 SYNOPSIS
  112.  
  113. See L<POE::Loop>.
  114.  
  115. =head1 DESCRIPTION
  116.  
  117. This class is an implementation of the signal handling functions
  118. defined by the abstract POE::Loop interface.  It follows POE::Loop's
  119. public interface for signal handling exactly.  Therefore, please see
  120. L<POE::Loop> for its documentation.
  121.  
  122. =head1 SEE ALSO
  123.  
  124. L<POE>, L<POE::Loop>
  125.  
  126. =head1 AUTHORS & LICENSING
  127.  
  128. Please see L<POE> for more information about authors, contributors,
  129. and POE's licensing.
  130.  
  131. =cut
  132.