ã¡ã¢æ¸ãç¨åº¦ã«ã
æºå
POE ã®å¤ãã®ã¯ã©ã¹ã¯ãPOE::Kernel ã«å¯¾ãã mix-in ã¨ãªã£ã¦ãã¾ããã¤ã¾ããPOE::Kernel ããã±ã¼ã¸ã«å±ããã¡ã½ãããªã®ã«ãKernel.pm ã«ãªããã ãã©â¦!! ã¨ãããã¨ãããèµ·ãããããããªãã¨ãããããã«ãã¨ãããã TAGS ãã¡ã¤ã«ãä½ã£ã¦ããã¾ãã
$ DIR=/opt/local/lib/perl5/site_perl/5.10.0/ $ etags $DIR/POE.pm `find $DIR/POE -type f`
mix-in ãªã®ã§ãåºæ¬çã«ã¯ã¡ã½ããã®å¤ãã POE::Kernel ã«å±ãã¾ãããããã§ã¯ä¾¿å®ä¸ãPOE/hoge.pm ã«æ¸ããã¦ããã¡ã½ãã㯠POE::hoge::method ã¨è¨è¿°ãã¾ãã
主ãªæµã
POE ã®ä¸»ãªå¦çã¯ãPOE::Kernel::run ã®å¼ã³åºãããå§ã¾ãã¾ããPOE::Kernel::run ã¯åå¦çãè¡ã£ãå¾ã§ãloop_run ãå¼ã³åºãã¾ãã
ãã® loop_run ã¯ãPOE::Loop ã®ãµãã¯ã©ã¹ã§å®ç¾©ããã¦ãã¾ããPOE ã§ã¯ã¤ãã³ãã«ã¼ããå®è¡ããã¢ã¸ã¥ã¼ã«ããPOE::Kernel ã¨ã¯å¥ã«ãã¦ãã¦ããã®ã«ã¼ããæ
å½ããæ½è±¡ã¯ã©ã¹ã POE::Loop ã¨ãªã£ã¦ãã¾ããããã©ã«ãã§ã¯ãPOE::Loop::Select ãé¸ã°ããããã§ãã
POE::Loop::Select ã® loop_run ã¯ã表é¢ä¸ãé常ã«åç´ãªã¤ãã³ãã«ã¼ããæ§æãã¦ãã¾ããã¨ã¯ãããã¤ãã³ãã«ã¼ãã£ã¦ã ãããããããå½¢ã«ãªããã®ã ã¨ã¯æãã¾ããã
sub loop_run { my $self = shift; # Run for as long as there are sessions to service. while ($self->_data_ses_count()) { $self->loop_do_timeslice(); } }
ããã§ã¯ãPOE::Session ãæ®ã£ã¦ããéããã«ã¼ãå¦çãå®è¡ãã¾ãã
POE::Loop::Select::loop_do_timeslice ã§ã¯ããããã select(2) ãå¼ã³åºããç£è¦å¯¾è±¡ã¨ãªããã¡ã¤ã«ãã³ãã«ã®å¤åããã§ãã¯ããããã¦ãã¾ã(ãã¡ãããç£è¦å¯¾è±¡ã¨ãªããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ãæå®ããå ´åã§ãã)ã
# Check filehandles, or wait for a period of time to elapse. my $hits = CORE::select( my $rout = $loop_vectors[MODE_RD], my $wout = $loop_vectors[MODE_WR], my $eout = $loop_vectors[MODE_EX], $timeout, );
ããã§ã® select(2) ã®å¼ã³åºãã¯ãsleep å¼ã³åºãã¨åãæå³åããæã£ã¦ãã¾ããã¤ã¾ãã次ã®ã¤ãã³ããçºçããã¾ã§ä¸å®æéå¾
æ©ããã¨ãããã¨ã§ã(ãã¡ããããã®å¾
æ©ä¸ã«ãã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã«å¤åãããã°ãselect(2) ãè¿ã£ã¦ãã¾ã)ã
ããã§ã¯ãä½ããã®å¤åããã¨ãã°ç£è¦å¯¾è±¡ã¨ãªããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã¸ã®æ¸ãè¾¼ã¿ãèµ·ããã¨ãã¤ãã³ããã¥ã¼ã«ãã®æ¨ã追å ããã®ã§ãããä»åã¯ä½ãèµ·ããããselect(2) ãã¿ã¤ã ã¢ã¦ããã¦è¿ã£ã¦ããå ´åãèãã¾ãã
select(2) ã«æ¸¡ãã¿ã¤ã ã¢ã¦ãå¤ã¯ã次ã®ã¤ãã³ããçºçããã¾ã§ã®æéã表ãã¦ãã¾ããã¤ã¾ããselect(2) ãã¿ã¤ã ã¢ã¦ãããã¨ããç¶æ ã¯ãPOE ãä½ããã®ã¤ãã³ããå¦çããæéã§ãããã¨ãæå³ãã¦ããããã§ãPOE::Loop::Select::loop_do_timeslice ã§ã¯ã¡ã½ãã POE::Resource::Events::_data_ev_dispatch_due ãå¼ã³ã ãã¾ãã
# Dispatch whatever events are due. $self->_data_ev_dispatch_due();
å¼ã³åºããã POE::Resource::Events::_data_ev_dispatch_due ã¤ãã³ããã¥ã¼ãã次ã«èµ·ãã event ãåå¾ããPOE::Kernel::_dispatch_event ãå¼ã³åºãã¾ãã
while (defined($next_time = $kr_queue->get_next_priority())) { last if $next_time > $now; my ($due_time, $id, $event) = $kr_queue->dequeue_next(); # ç¥ $self->_data_ev_refcount_dec($event->[EV_SOURCE], $event->[EV_SESSION]); $self->_dispatch_event(@$event, $due_time, $id);
ãã®ã¤ãã³ãã¯ã·ã°ãã«å¦çã ã£ãããselect(2) ã«ãã£ã¦æ¤ç¥ãããã¡ã¤ã«ãã£ã¹ã¯ãªãã¿ã®å¤åã¤ãã³ãã ã£ãããã¾ãããä»åã¯ä¸çªã¹ã¿ã³ãã¼ããªã¤ãã³ãã追ã£ã¦ã¿ã¾ãã
å®ã¯ãã®æ®µé(POE::Kernel::_dispatch_event)ã§ãã¤ãã³ããã©ã® POE::Session ã«éããªãã¨ãããªããã¯ãPOE::Kernel::_dispatch_event ã«ã¯åãã£ã¦ãã¾ã(POE::Resource::Events::_data_ev_dispatch_due ãã渡ããã¾ã)ãPOE::Kernel ã¯ãã® POE::Session ã® _invoke_state ãå¼ã³åºãã¾ããPOE::Session::_invoke_state ã§ã¯å®éã«æå®ãããã»ãã·ã§ã³ã®æå®ãããç¶æ ã«ãããã³ã¼ããªãã¡ã¬ã³ã¹ãå®è¡ãã¾ããå¼ã³åºãã¯ãããªæã(inline_state ã®å ´å)ã
if (ref($self->[SE_STATES]->{$state}) eq 'CODE') { return $self->[SE_STATES]->{$state}-> ( undef, # object $self, # session $POE::Kernel::poe_kernel, # kernel $self->[SE_NAMESPACE], # heap $state, # state $source_session, # sender undef, # unused #6 $file, # caller file name $line, # caller file line $fromstate, # caller state @$etc # args ); }