{
    "content": [
        {
            "type": "text",
            "text": "# IO::Select (perldoc)\n\n## NAME\n\nIO::Select - OO interface to the select system call\n\n## SYNOPSIS\n\nuse IO::Select;\n$s = IO::Select->new();\n$s->add(\\*STDIN);\n$s->add($somehandle);\n@ready = $s->canread($timeout);\n@ready = IO::Select->new(@handles)->canread(0);\n\n## DESCRIPTION\n\nThe \"IO::Select\" package implements an object approach to the system \"select\" function call. It\nallows the user to see what IO handles, see IO::Handle, are ready for reading, writing or have\nan exception pending.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **CONSTRUCTOR**\n- **METHODS** (1 subsections)\n- **EXAMPLE**\n- **AUTHOR**\n- **COPYRIGHT**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "IO::Select",
        "section": "",
        "mode": "perldoc",
        "summary": "IO::Select - OO interface to the select system call",
        "synopsis": "use IO::Select;\n$s = IO::Select->new();\n$s->add(\\*STDIN);\n$s->add($somehandle);\n@ready = $s->canread($timeout);\n@ready = IO::Select->new(@handles)->canread(0);",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "Here is a short example which shows how \"IO::Select\" could be used to write a server which",
            "communicates with several sockets while also listening for more connections on a listen socket",
            "use IO::Select;",
            "use IO::Socket;",
            "$lsn = IO::Socket::INET->new(Listen => 1, LocalPort => 8080);",
            "$sel = IO::Select->new( $lsn );",
            "while(@ready = $sel->canread) {",
            "foreach $fh (@ready) {",
            "if($fh == $lsn) {",
            "# Create a new socket",
            "$new = $lsn->accept;",
            "$sel->add($new);",
            "else {",
            "# Process socket",
            "# Maybe we have finished with the socket",
            "$sel->remove($fh);",
            "$fh->close;"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "CONSTRUCTOR",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 39,
                "subsections": [
                    {
                        "name": "bits",
                        "lines": 14
                    }
                ]
            },
            {
                "name": "EXAMPLE",
                "lines": 26,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "COPYRIGHT",
                "lines": 3,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "IO::Select - OO interface to the select system call\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use IO::Select;\n\n$s = IO::Select->new();\n\n$s->add(\\*STDIN);\n$s->add($somehandle);\n\n@ready = $s->canread($timeout);\n\n@ready = IO::Select->new(@handles)->canread(0);\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "The \"IO::Select\" package implements an object approach to the system \"select\" function call. It\nallows the user to see what IO handles, see IO::Handle, are ready for reading, writing or have\nan exception pending.\n",
                "subsections": []
            },
            "CONSTRUCTOR": {
                "content": "new ( [ HANDLES ] )\nThe constructor creates a new object and optionally initialises it with a set of handles.\n",
                "subsections": []
            },
            "METHODS": {
                "content": "add ( HANDLES )\nAdd the list of handles to the \"IO::Select\" object. It is these values that will be returned\nwhen an event occurs. \"IO::Select\" keeps these values in a cache which is indexed by the\n\"fileno\" of the handle, so if more than one handle with the same \"fileno\" is specified then\nonly the last one is cached.\n\nEach handle can be an \"IO::Handle\" object, an integer or an array reference where the first\nelement is an \"IO::Handle\" or an integer.\n\nremove ( HANDLES )\nRemove all the given handles from the object. This method also works by the \"fileno\" of the\nhandles. So the exact handles that were added need not be passed, just handles that have an\nequivalent \"fileno\"\n\nexists ( HANDLE )\nReturns a true value (actually the handle itself) if it is present. Returns undef otherwise.\n\nhandles\nReturn an array of all registered handles.\n\ncanread ( [ TIMEOUT ] )\nReturn an array of handles that are ready for reading. \"TIMEOUT\" is the maximum amount of\ntime to wait before returning an empty list (with $! unchanged), in seconds, possibly\nfractional. If \"TIMEOUT\" is not given and any handles are registered then the call will\nblock indefinitely. Upon error, an empty list is returned, with $! set to indicate the\nerror. To distinguish between timeout and error, set $! to zero before calling this method,\nand check it after an empty list is returned.\n\ncanwrite ( [ TIMEOUT ] )\nSame as \"canread\" except check for handles that can be written to.\n\nhasexception ( [ TIMEOUT ] )\nSame as \"canread\" except check for handles that have an exception condition, for example\npending out-of-band data.\n\ncount ()\nReturns the number of handles that the object will check for when one of the \"can\" methods\nis called or the object is passed to the \"select\" static method.\n",
                "subsections": [
                    {
                        "name": "bits",
                        "content": "Return the bit string suitable as argument to the core select() call.\n\nselect ( READ, WRITE, EXCEPTION [, TIMEOUT ] )\n\"select\" is a static method, that is you call it with the package name like \"new\". \"READ\",\n\"WRITE\" and \"EXCEPTION\" are either \"undef\" or \"IO::Select\" objects. \"TIMEOUT\" is optional\nand has the same effect as for the core select call.\n\nIf at least one handle is ready for the specified kind of operation, the result will be an\narray of 3 elements, each a reference to an array which will hold the handles that are ready\nfor reading, writing and have exceptions respectively. Upon timeout, an empty list is\nreturned, with $! unchanged. Upon error, an empty list is returned, with $! set to indicate\nthe error. To distinguish between timeout and error, set $! to zero before calling this\nmethod, and check it after an empty list is returned.\n"
                    }
                ]
            },
            "EXAMPLE": {
                "content": "Here is a short example which shows how \"IO::Select\" could be used to write a server which\ncommunicates with several sockets while also listening for more connections on a listen socket\n\nuse IO::Select;\nuse IO::Socket;\n\n$lsn = IO::Socket::INET->new(Listen => 1, LocalPort => 8080);\n$sel = IO::Select->new( $lsn );\n\nwhile(@ready = $sel->canread) {\nforeach $fh (@ready) {\nif($fh == $lsn) {\n# Create a new socket\n$new = $lsn->accept;\n$sel->add($new);\n}\nelse {\n# Process socket\n\n# Maybe we have finished with the socket\n$sel->remove($fh);\n$fh->close;\n}\n}\n}\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Graham Barr. Currently maintained by the Perl Porters. Please report all bugs to\n<perlbug@perl.org>.\n",
                "subsections": []
            },
            "COPYRIGHT": {
                "content": "Copyright (c) 1997-8 Graham Barr <gbarr@pobox.com>. All rights reserved. This program is free\nsoftware; you can redistribute it and/or modify it under the same terms as Perl itself.\n",
                "subsections": []
            }
        }
    }
}