{
    "content": [
        {
            "type": "text",
            "text": "# POE::Wheel::ListenAccept (perldoc)\n\n## NAME\n\nPOE::Wheel::ListenAccept - accept connections from regular listening sockets\n\n## SYNOPSIS\n\nSee \"SYNOPSIS\" in POE::Wheel::SocketFactory for a simpler version of this program.\n#!perl\nuse warnings;\nuse strict;\nuse IO::Socket;\nuse POE qw(Wheel::ListenAccept Wheel::ReadWrite);\nPOE::Session->create(\ninlinestates => {\nstart => sub {\n# Start the server.\n$[HEAP]{server} = POE::Wheel::ListenAccept->new(\nHandle => IO::Socket::INET->new(\nLocalPort => 12345,\nListen => 5,\n),\nAcceptEvent => \"onclientaccept\",\nErrorEvent => \"onservererror\",\n);\n},\nonclientaccept => sub {\n# Begin interacting with the client.\nmy $clientsocket = $[ARG0];\nmy $iowheel = POE::Wheel::ReadWrite->new(\nHandle => $clientsocket,\nInputEvent => \"onclientinput\",\nErrorEvent => \"onclienterror\",\n);\n$[HEAP]{client}{ $iowheel->ID() } = $iowheel;\n},\nonservererror => sub {\n# Shut down server.\nmy ($operation, $errnum, $errstr) = @[ARG0, ARG1, ARG2];\nwarn \"Server $operation error $errnum: $errstr\\n\";\ndelete $[HEAP]{server};\n},\nonclientinput => sub {\n# Handle client input.\nmy ($input, $wheelid) = @[ARG0, ARG1];\n$input =~ tr[a-zA-Z][n-za-mN-ZA-M]; # ASCII rot13\n$[HEAP]{client}{$wheelid}->put($input);\n},\nonclienterror => sub {\n# Handle client error, including disconnect.\nmy $wheelid = $[ARG3];\ndelete $[HEAP]{client}{$wheelid};\n},\n}\n);\nPOE::Kernel->run();\nexit;\n\n## DESCRIPTION\n\nPOE::Wheel::ListenAccept implements non-blocking accept() calls for plain old listening server\nsockets. The application provides the socket, using some normal means such as socket(),\nIO::Socket::INET, or IO::Socket::UNIX. POE::Wheel::ListenAccept monitors the listening socket\nand emits events whenever a new client has been accepted.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **PUBLIC METHODS** (3 subsections)\n- **PUBLIC EVENTS** (2 subsections)\n- **SEE ALSO**\n- **BUGS**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "POE::Wheel::ListenAccept",
        "section": "",
        "mode": "perldoc",
        "summary": "POE::Wheel::ListenAccept - accept connections from regular listening sockets",
        "synopsis": "See \"SYNOPSIS\" in POE::Wheel::SocketFactory for a simpler version of this program.\n#!perl\nuse warnings;\nuse strict;\nuse IO::Socket;\nuse POE qw(Wheel::ListenAccept Wheel::ReadWrite);\nPOE::Session->create(\ninlinestates => {\nstart => sub {\n# Start the server.\n$[HEAP]{server} = POE::Wheel::ListenAccept->new(\nHandle => IO::Socket::INET->new(\nLocalPort => 12345,\nListen => 5,\n),\nAcceptEvent => \"onclientaccept\",\nErrorEvent => \"onservererror\",\n);\n},\nonclientaccept => sub {\n# Begin interacting with the client.\nmy $clientsocket = $[ARG0];\nmy $iowheel = POE::Wheel::ReadWrite->new(\nHandle => $clientsocket,\nInputEvent => \"onclientinput\",\nErrorEvent => \"onclienterror\",\n);\n$[HEAP]{client}{ $iowheel->ID() } = $iowheel;\n},\nonservererror => sub {\n# Shut down server.\nmy ($operation, $errnum, $errstr) = @[ARG0, ARG1, ARG2];\nwarn \"Server $operation error $errnum: $errstr\\n\";\ndelete $[HEAP]{server};\n},\nonclientinput => sub {\n# Handle client input.\nmy ($input, $wheelid) = @[ARG0, ARG1];\n$input =~ tr[a-zA-Z][n-za-mN-ZA-M]; # ASCII rot13\n$[HEAP]{client}{$wheelid}->put($input);\n},\nonclienterror => sub {\n# Handle client error, including disconnect.\nmy $wheelid = $[ARG3];\ndelete $[HEAP]{client}{$wheelid};\n},\n}\n);\nPOE::Kernel->run();\nexit;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 56,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 12,
                "subsections": []
            },
            {
                "name": "PUBLIC METHODS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "new",
                        "lines": 2
                    },
                    {
                        "name": "new",
                        "lines": 13
                    },
                    {
                        "name": "event",
                        "lines": 23
                    }
                ]
            },
            {
                "name": "PUBLIC EVENTS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "AcceptEvent",
                        "lines": 31
                    },
                    {
                        "name": "ErrorEvent",
                        "lines": 21
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "POE::Wheel::ListenAccept - accept connections from regular listening sockets\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "See \"SYNOPSIS\" in POE::Wheel::SocketFactory for a simpler version of this program.\n\n#!perl\n\nuse warnings;\nuse strict;\n\nuse IO::Socket;\nuse POE qw(Wheel::ListenAccept Wheel::ReadWrite);\n\nPOE::Session->create(\ninlinestates => {\nstart => sub {\n# Start the server.\n$[HEAP]{server} = POE::Wheel::ListenAccept->new(\nHandle => IO::Socket::INET->new(\nLocalPort => 12345,\nListen => 5,\n),\nAcceptEvent => \"onclientaccept\",\nErrorEvent => \"onservererror\",\n);\n},\nonclientaccept => sub {\n# Begin interacting with the client.\nmy $clientsocket = $[ARG0];\nmy $iowheel = POE::Wheel::ReadWrite->new(\nHandle => $clientsocket,\nInputEvent => \"onclientinput\",\nErrorEvent => \"onclienterror\",\n);\n$[HEAP]{client}{ $iowheel->ID() } = $iowheel;\n},\nonservererror => sub {\n# Shut down server.\nmy ($operation, $errnum, $errstr) = @[ARG0, ARG1, ARG2];\nwarn \"Server $operation error $errnum: $errstr\\n\";\ndelete $[HEAP]{server};\n},\nonclientinput => sub {\n# Handle client input.\nmy ($input, $wheelid) = @[ARG0, ARG1];\n$input =~ tr[a-zA-Z][n-za-mN-ZA-M]; # ASCII rot13\n$[HEAP]{client}{$wheelid}->put($input);\n},\nonclienterror => sub {\n# Handle client error, including disconnect.\nmy $wheelid = $[ARG3];\ndelete $[HEAP]{client}{$wheelid};\n},\n}\n);\n\nPOE::Kernel->run();\nexit;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "POE::Wheel::ListenAccept implements non-blocking accept() calls for plain old listening server\nsockets. The application provides the socket, using some normal means such as socket(),\nIO::Socket::INET, or IO::Socket::UNIX. POE::Wheel::ListenAccept monitors the listening socket\nand emits events whenever a new client has been accepted.\n\nPlease see POE::Wheel::SocketFactory if you need non-blocking connect() or a more featureful\nlisten/accept solution.\n\nPOE::Wheel::ListenAccept only accepts client connections. It does not read or write data, so it\nneither needs nor includes a put() method. POE::Wheel::ReadWrite generally handles the accepted\nclient socket.\n",
                "subsections": []
            },
            "PUBLIC METHODS": {
                "content": "new",
                "subsections": [
                    {
                        "name": "new",
                        "content": "will generate events relating to the socket for as long as it exists.\n"
                    },
                    {
                        "name": "new",
                        "content": "Handle\nThe \"Handle\" constructor parameter must contain a listening socket handle.\nPOE::Wheel::FollowTail will monitor this socket and accept() new connections as they arrive.\n\nAcceptEvent\n\"AcceptEvent\" is a required event name that POE::Wheel::ListenAccept will emit for each accepted\nclient socket. \"PUBLIC EVENTS\" describes it in detail\n\nErrorEvent\n\"ErrorEvent\" is an optional event name that will be emitted whenever a serious problem occurs.\nPlease see \"PUBLIC EVENTS\" for more details.\n\nevent"
                    },
                    {
                        "name": "event",
                        "content": "re-creating the object. It accepts one or more of the events listed in \"PUBLIC EVENTS\".\nUndefined event names disable those events.\n\nIgnore connections:\n\nsub ignorenewconnections {\n$[HEAP]{tailor}->event( AcceptEvent => \"onignoredaccept\" );\n}\n\nsub handleignoredaccept {\n# does nothing\n}\n\nID\nThe ID() method returns the wheel's unique ID. It's useful for storing the wheel in a hash. All\nPOE::Wheel events should be accompanied by a wheel ID, which allows the wheel to be referenced\nin their event handlers.\n\nsub setuplistener {\nmy $wheel = POE::Wheel::ListenAccept->new(... etc  ...);\n$[HEAP]{listeners}{$wheel->ID} = $wheel;\n}\n"
                    }
                ]
            },
            "PUBLIC EVENTS": {
                "content": "POE::Wheel::ListenAccept emits a couple events.\n",
                "subsections": [
                    {
                        "name": "AcceptEvent",
                        "content": "\"AcceptEvent\" names the event that will be emitted for each newly accepted client socket. It is\naccompanied by three parameters:\n\n$[ARG0] contains the newly accepted client socket handle. It's up to the application to do\nsomething with this socket. Most use cases involve passing the socket to a POE::Wheel::ReadWrite\nconstructor.\n\n$[ARG1] contains the accept() call's return value, which is often the encoded remote end of the\nremote end of the socket.\n\n$[ARG2] contains the POE::Wheel::ListenAccept object's unique ID. This is the same value as\nreturned by the wheel's ID() method.\n\nA sample \"AcceptEvent\" handler:\n\nsub acceptstate {\nmy ($clientsocket, $remoteaddr, $wheelid) = @[ARG0..ARG2];\n\n# Make the remote address human readable.\nmy ($port, $packedip) = sockaddrin($remoteaddr);\nmy $dottedquad = inetntoa($packedip);\n\nprint(\n\"Wheel $wheelid accepted a connection from \",\n\"$dottedquad port $port.\\n\"\n);\n\n# Spawn off a session to interact with the socket.\ncreateserversession($handle);\n}\n"
                    },
                    {
                        "name": "ErrorEvent",
                        "content": "\"ErrorEvent\" names the event that will be generated whenever a new connection could not be\nsuccessfully accepted. This event is accompanied by four parameters:\n\n$[ARG0] contains the name of the operation that failed. This usually is 'accept', but be aware\nthat it's not necessarily a function name.\n\n$[ARG1] and $[ARG2] hold the numeric and stringified values of $!, respectively.\nPOE::Wheel::ListenAccept knows how to handle EAGAIN (and system-dependent equivalents), so this\nerror will never be returned.\n\n$[ARG3] contains the wheel's unique ID, which may be useful for shutting down one particular\nwheel out of a group of them.\n\nA sample \"ErrorEvent\" event handler. This assumes the wheels are saved as in the \"ID\" example.\n\nsub errorstate {\nmy ($operation, $errnum, $errstr, $wheelid) = @[ARG0..ARG3];\nwarn \"Wheel $wheelid generated $operation error $errnum: $errstr\\n\";\ndelete $[HEAP]{listeners}{$wheelid};\n}\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "POE::Wheel describes the basic operations of all wheels in more depth. You need to know this.\n\nPOE::Wheel::ReadWrite for one possible way to handle clients once you have their sockets.\n\nThe SEE ALSO section in POE contains a table of contents covering the entire POE distribution.\n",
                "subsections": []
            },
            "BUGS": {
                "content": "None known.\n\nAUTHORS & COPYRIGHTS\nPlease see POE for more information about authors and contributors.\n",
                "subsections": []
            }
        }
    }
}