{
    "content": [
        {
            "type": "text",
            "text": "# Net::Server::SIG (perldoc)\n\n## NAME\n\nNet::Server::SIG - adpf - Safer signal handling\n\n## SYNOPSIS\n\nuse Net::Server::SIG qw(registersig checksigs);\nuse IO::Select ();\nuse POSIX qw(WNOHANG);\nmy $select = IO::Select->new();\nregistersig(PIPE => 'IGNORE',\nHUP  => 'DEFAULT',\nUSR1 => sub { print \"I got a SIG $[0]\\n\"; },\nUSR2 => sub { print \"I got a SIG $[0]\\n\"; },\nCHLD => sub { 1 while waitpid(-1, WNOHANG) > 0; },\n);\n# add some handles to the select\n$select->add(\\*STDIN);\n# loop forever trying to stay alive\nwhile (1) {\n# do a timeout to see if any signals got passed us\n# while we were processing another signal\nmy @fh = $select->canread(10);\nmy $key;\nmy $val;\n# this is the handler for safe (fine under unsafe also)\nif (checksigs()) {\n# or my @sigs = checksigs();\nnext unless @fh;\n}\nmy $handle = $fh[@fh];\n# do something with the handle\n}\n\n## DESCRIPTION\n\nSignals prior in Perl prior to 5.7 were unsafe. Since then signals have been implemented in a\nmore safe algorithm. Net::Server::SIG provides backwards compatibility, while still working\nreliably with newer releases.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **FUNCTIONS**\n- **AUTHORS**\n- **LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Net::Server::SIG",
        "section": "",
        "mode": "perldoc",
        "summary": "Net::Server::SIG - adpf - Safer signal handling",
        "synopsis": "use Net::Server::SIG qw(registersig checksigs);\nuse IO::Select ();\nuse POSIX qw(WNOHANG);\nmy $select = IO::Select->new();\nregistersig(PIPE => 'IGNORE',\nHUP  => 'DEFAULT',\nUSR1 => sub { print \"I got a SIG $[0]\\n\"; },\nUSR2 => sub { print \"I got a SIG $[0]\\n\"; },\nCHLD => sub { 1 while waitpid(-1, WNOHANG) > 0; },\n);\n# add some handles to the select\n$select->add(\\*STDIN);\n# loop forever trying to stay alive\nwhile (1) {\n# do a timeout to see if any signals got passed us\n# while we were processing another signal\nmy @fh = $select->canread(10);\nmy $key;\nmy $val;\n# this is the handler for safe (fine under unsafe also)\nif (checksigs()) {\n# or my @sigs = checksigs();\nnext unless @fh;\n}\nmy $handle = $fh[@fh];\n# do something with the handle\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 38,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "FUNCTIONS",
                "lines": 18,
                "subsections": []
            },
            {
                "name": "AUTHORS",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Net::Server::SIG - adpf - Safer signal handling\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use Net::Server::SIG qw(registersig checksigs);\nuse IO::Select ();\nuse POSIX qw(WNOHANG);\n\nmy $select = IO::Select->new();\n\nregistersig(PIPE => 'IGNORE',\nHUP  => 'DEFAULT',\nUSR1 => sub { print \"I got a SIG $[0]\\n\"; },\nUSR2 => sub { print \"I got a SIG $[0]\\n\"; },\nCHLD => sub { 1 while waitpid(-1, WNOHANG) > 0; },\n);\n\n# add some handles to the select\n$select->add(\\*STDIN);\n\n# loop forever trying to stay alive\nwhile (1) {\n\n# do a timeout to see if any signals got passed us\n# while we were processing another signal\nmy @fh = $select->canread(10);\n\nmy $key;\nmy $val;\n\n# this is the handler for safe (fine under unsafe also)\nif (checksigs()) {\n# or my @sigs = checksigs();\nnext unless @fh;\n}\n\nmy $handle = $fh[@fh];\n\n# do something with the handle\n\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Signals prior in Perl prior to 5.7 were unsafe. Since then signals have been implemented in a\nmore safe algorithm. Net::Server::SIG provides backwards compatibility, while still working\nreliably with newer releases.\n\nUsing a property of the select() function, Net::Server::SIG attempts to fix the unsafe problem.\nIf a process is blocking on select() any signal will short circuit the select. Using this\nconcept, Net::Server::SIG does the least work possible (changing one bit from 0 to 1). And\ndepends upon the actual processing of the signals to take place immediately after the select\ncall via the \"checksigs\" function. See the example shown above and also see the sigtest.pl\nscript located in the examples directory of this distribution.\n",
                "subsections": []
            },
            "FUNCTIONS": {
                "content": "\"registersig($SIG => \\&coderef)\"\nTakes key/value pairs where the key is the signal name, and the argument is either a code\nref, or the words 'DEFAULT' or 'IGNORE'. The function registersig must be used in\nconjunction with checksigs, and with a blocking select() function call -- otherwise, you\nwill observe the registered signal mysteriously vanish.\n\n\"unregistersig($SIG)\"\nTakes the name of a signal as an argument. Calls registersig with a this signal name and\n'DEFAULT' as arguments (same as registersig(SIG,'DEFAULT')\n\n\"checksigs()\"\nChecks to see if any registered signals have occurred. If so, it will play the registered\ncode ref for that signal. Return value is array containing any SIGNAL names that had\noccurred.\n\n\"sigisregistered($SIG)\"\nTakes a signal name and returns any registered coderef for that signal.\n",
                "subsections": []
            },
            "AUTHORS": {
                "content": "Paul Seamons (paul@seamons.com)\n\nRob B Brown (rob@roobik.com) - Provided a sounding board and feedback in creating\nNet::Server::SIG and sigtest.pl.\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "This package may be distributed under the terms of either the\nGNU General Public License\nor the\nPerl Artistic License\n\nAll rights reserved.\n",
                "subsections": []
            }
        }
    }
}