The document discusses the Lua virtual machine (LuaVM) bytecode format and instructions. It shows an example Lua function written in bytecode format, with each instruction taking up one bytecode. The bytecode format uses registers to reference values on the stack and constants to reference values in the constant table. Common Lua operations like variable assignment and table indexing can be represented in a single bytecode instruction this way.
The document discusses the Lua virtual machine (LuaVM) bytecode format and instructions. It shows an example Lua function written in bytecode format, with each instruction taking up one bytecode. The bytecode format uses registers to reference values on the stack and constants to reference values in the constant table. Common Lua operations like variable assignment and table indexing can be represented in a single bytecode instruction this way.
8. PreFork サーバ (concurrent server) use strict; use warnings; use IO::Socket; use POSIX 'WNOHANG'; my $socket = IO::Socket::INET->new( Listen => 20, LocalPort => 12345 ) or die; for ( 1 .. 5 ) { my $pid = fork; if ( $pid == 0 ) { ## child while ( my $con = $socket->accept ) { close $socket; my $line = <$con>; print $con $line; close $con; } exit(0); } } ## parent; $SIG{CHLD} = sub { while ( waitpid( -1, WNOHANG ) > 0 ) { } }; while (1) { ## 子プロセスの数を調整するなど色々 } 確立待ちコネクションキュー 確立済みコネクションキュー Listen キュー 子 子 子 accept accept accept
9. Net::Server lib `-- Net |-- Server | |-- Daemonize.pm | |-- Fork.pm | |-- HTTP.pm | |-- INET.pm | |-- MultiType.pm | |-- Multiplex.pm | |-- PreFork.pm | |-- PreForkSimple.pm | |-- Proto | | |-- SSL.pm | | |-- SSLEAY.pm | | |-- TCP.pm | | |-- UDP.pm | | `-- UNIX.pm | |-- Proto.pm | |-- SIG.pm | `-- Single.pm |-- Server.pm `-- Server.pod 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 }