- # Child. Clear the child process list.
- $kernel->has_forked();
- DEBUG and warn "Server $$ forked successfully.\n";
- $heap->{is_a_child} = 1;
- $heap->{children} = {};
-
- return;
- }
-}
-
-### The server session received SIGINT. Don't handle the signal,
-### which in turn will trigger the process to exit gracefully.
-
-sub server_got_sig_int {
- DEBUG and warn "Server $$ received SIGINT.\n";
- delete $_[HEAP]->{server};
- $_[KERNEL]->sig_handled();
-}
-
-### The server session received a SIGCHLD, indicating that some child
-### server has gone away. Remove the child's process ID from our
-### list, and trigger more fork() calls to spawn new children.
-
-sub server_got_sig_child {
- my ( $kernel, $heap, $child_pid ) = @_[ KERNEL, HEAP, ARG1 ];
-
- return unless delete $heap->{children}->{$child_pid};
-
- DEBUG and warn "Server $$ reaped child $child_pid.\n";
- $kernel->yield("do_fork") if exists $_[HEAP]->{server};
-}
-
-### The server session received a connection request. Spawn off a
-### client handler session to parse the request and respond to it.
-
-sub server_got_connection {
- my ( $heap, $socket, $peer_addr, $peer_port ) = @_[ HEAP, ARG0, ARG1, ARG2 ];
-
- DEBUG and warn "Server $$ received a connection.\n";
-
- POE::Session->create(
- inline_states => {
- _start => \&client_start,
- _stop => \&client_stop,
- got_request => \&client_got_request,
- got_flush => \&client_flushed_request,
- got_error => \&client_got_error,
- _parent => sub { 0 },
- },
- heap => {
- socket => $socket,
- peer_addr => $peer_addr,
- peer_port => $peer_port,
- },
- );
-
- # Gracefully exit if testing process churn.
- delete $heap->{server}
- if TESTING_CHURN and $heap->{is_a_child} and ( rand() < 0.1 );
-}
-
-### The client handler has started. Wrap its socket in a ReadWrite
-### wheel to begin interacting with it.
-
-sub client_start {
- my $heap = $_[HEAP];
-
- $heap->{client} = POE::Wheel::ReadWrite->new
- ( Handle => $heap->{socket},
- Filter => POE::Filter::HTTPD->new(),
- InputEvent => "got_request",
- ErrorEvent => "got_error",
- FlushedEvent => "got_flush",
- );
-
- DEBUG and warn "Client handler $$/", $_[SESSION]->ID, " started.\n";
-}
-
-### The client handler has stopped. Log that fact.
-
-sub client_stop {
- DEBUG and warn "Client handler $$/", $_[SESSION]->ID, " stopped.\n";
-}
-
-### The client handler has received a request. If it's an
-### HTTP::Response object, it means some error has occurred while
-### parsing the request. Send that back and return immediately.
-### Otherwise parse and process the request, generating and sending an
-### HTTP::Response object in response.
-
-sub client_got_request {
- my ( $heap, $request ) = @_[ HEAP, ARG0 ];
-
- freeside_kid_time();