1Net::Server::SIG(3)   User Contributed Perl Documentation  Net::Server::SIG(3)
2
3
4

NAME

6       Net::Server::SIG - adpf - Safer signal handling
7

SYNOPSIS

9           use Net::Server::SIG qw(register_sig check_sigs);
10           use IO::Select ();
11           use POSIX qw(WNOHANG);
12
13           my $select = IO::Select->new();
14
15           register_sig(PIPE => 'IGNORE',
16                        HUP  => 'DEFAULT',
17                        USR1 => sub { print "I got a SIG $_[0]\n"; },
18                        USR2 => sub { print "I got a SIG $_[0]\n"; },
19                        CHLD => sub { 1 while waitpid(-1, WNOHANG) > 0; },
20                        );
21
22           # add some handles to the select
23           $select->add(\*STDIN);
24
25           # loop forever trying to stay alive
26           while (1) {
27
28               # do a timeout to see if any signals got passed us
29               # while we were processing another signal
30               my @fh = $select->can_read(10);
31
32               my $key;
33               my $val;
34
35               # this is the handler for safe (fine under unsafe also)
36               if (check_sigs()) {
37                 # or my @sigs = check_sigs();
38                 next unless @fh;
39               }
40
41               my $handle = $fh[@fh];
42
43               # do something with the handle
44
45           }
46

DESCRIPTION

48       Signals prior in Perl prior to 5.7 were unsafe.  Since then signals
49       have been implemented in a more safe algorithm.  Net::Server::SIG
50       provides backwards compatibility, while still working reliably with
51       newer releases.
52
53       Using a property of the select() function, Net::Server::SIG attempts to
54       fix the unsafe problem.  If a process is blocking on select() any
55       signal will short circuit the select.  Using this concept,
56       Net::Server::SIG does the least work possible (changing one bit from 0
57       to 1).  And depends upon the actual processing of the signals to take
58       place immediately after the the select call via the "check_sigs"
59       function.  See the example shown above and also see the sigtest.pl
60       script located in the examples directory of this distribution.
61

FUNCTIONS

63       "register_sig($SIG => \&code_ref)"
64           Takes key/value pairs where the key is the signal name, and the
65           argument is either a code ref, or the words 'DEFAULT' or 'IGNORE'.
66           The function register_sig must be used in conjunction with
67           check_sigs, and with a blocking select() function call --
68           otherwise, you will observe the registered signal mysteriously
69           vanish.
70
71       "unregister_sig($SIG)"
72           Takes the name of a signal as an argument.  Calls register_sig with
73           a this signal name and 'DEFAULT' as arguments (same as
74           register_sig(SIG,'DEFAULT')
75
76       "check_sigs()"
77           Checks to see if any registered signals have occured.  If so, it
78           will play the registered code ref for that signal.  Return value is
79           array containing any SIGNAL names that had occured.
80
81       "sig_is_registered($SIG)"
82           Takes a signal name and returns any registered code_ref for that
83           signal.
84

AUTHORS

86       Paul Seamons (paul@seamons.com)
87
88       Rob B Brown (rob@roobik.com) - Provided a sounding board and feedback
89       in creating Net::Server::SIG and sigtest.pl.
90

LICENSE

92         This package may be distributed under the terms of either the
93         GNU General Public License
94           or the
95         Perl Artistic License
96
97         All rights reserved.
98
99
100
101perl v5.32.0                      2020-07-28               Net::Server::SIG(3)
Impressum