# probe into Starman Process ## High-performance preforking PSGI/Plack web server ### {{cpan: Starman}} 0.2014 1. {{cpan: Starman::Server}} * run * pre_loop_hook * run_parent * child_init_hook * post_accept_hook * process_request * post_client_connection_hook 2. {{cpan: Net::Server::PreFork}} * options * post_configure * loop * kill_n_children * run_n_children * (run_n_children_hook) * run_child * run_parent * coordinate_children * delete_child * (parent_read_hook) * (child_is_talking_hook) 3. {{cpan: Net::Server::PreForkSimple}} * options * post_configure * post_bind * loop * run_n_children * (run_n_children_hook) * run_child * (child_init_hook) * (child_finish_hook) * accept * done * run_parent * (idle_loop_hook) * (run_dequeue) * close_children 4. {{cpan: Net::Server}} ### Net::Server: run sub run { ### pass package or object my $self = ref($_[0]) ? shift() : shift->new; $self->_initialize(@_ == 1 ? %{$_[0]} : @_); # configure all parameters $self->post_configure; # verification of passed parameters $self->post_configure_hook; # user customizable hook $self->pre_bind; # finalize ports to be bound $self->bind; # connect to port(s) # setup selection handle for multi port $self->post_bind_hook; # user customizable hook $self->post_bind; # allow for chrooting, # becoming a different user and group $self->pre_loop_hook; # user customizable hook $self->loop; # repeat accept/process cycle ### routines inside a standard $self->loop # $self->accept # wait for client connection # $self->run_client_connection # process client # $self->done # indicate if connection is done $self->server_close; # close the server and release the port # this will run pre_server_close_hook # close_children # post_child_cleanup_hook # shutdown_sockets # and either exit or run restart_close_hook } ### Net::Server: run_client_connection sub run_client_connection { my $self = shift; $self->post_accept; # prepare client for processing $self->get_client_info; # determines information about peer and local $self->post_accept_hook; # user customizable hook if( $self->allow_deny # do allow/deny check on client info && $self->allow_deny_hook ){ # user customizable hook $self->process_request; # This is where the core functionality # of a Net::Server should be. This is the # only method necessary to override. }else{ $self->request_denied_hook; # user customizable hook } $self->post_process_request_hook; # user customizable hook $self->post_process_request; # clean up client connection, etc $self->post_client_connection_hook; # one last hook } ### HOOKS: Net::Server::PreForkSimple #### $self->run_n_children_hook() This hook occurs at the top of run_n_children which is called each time the server goes to start more child processes. This gives the parent to do a little of its own accountting (as desired). #### $self->child_init_hook() This hook takes place immeditately after the child process forks from the parent and before the child begins accepting connections. It is intended for any addiotional chrooting or other security measures. It is suggested that all perl modules be used by this point, so that the most shared memory possible is used. #### $self->child_finish_hook() This hook takes place immediately before the child tells the parent that it is exiting. It is intended for saving out logged information or other general cleanup. #### $self->run_dequeue() This hook only gets called in conjuction with the check_for_dequeue setting. #### $self->idle_loop_hook() This hook is called in every pass through the main process wait loop.