Archive for the ‘Perl’ Category

perl poe

POE空框架。用于具体功能实现的代码将被添加到这个框架之中。 #!/usr/bin/perl use warnings; use strict; use POSIX; use IO::Socket; use POE; POE::Session->create ( inline_states => { } ); POE::Kernel->run(); exit; 在继续完成接下来的程序之前,为了勾勒出程序的大致框架结构,必须明确哪些事件的出现是必要的。 ? 服务器启动,完成初始化。 ? 服务器socket准备就绪,可以接收连接。 ? 客户socket处于可读取状态,服务器读取数据并对其进行处理。 ? 客户socket处于可写状态,服务器对其写入一些数据。 ? 客户socket发生错误,需要将其关闭。 一旦知道了需要做些什么,就可以建立这些事件的名称,并为这些事件编写相应的事件处理句柄,从而快速地完成POE::Session的构造。 POE::Session->create ( inline_states => { _start => \&server_start, event_accept => \&server_accept, event_read => \&client_read, event_write => \&client_write, event_error => \&client_error, } ); [...]

About the Perl EV (AnyEvent)module

BEFORE YOU START USING THIS MODULE If you only need timer, I/O, signal, child and idle watchers and not the advanced functionality of this module, consider using AnyEvent instead, specifically the simplified API described in AE. When used with EV as backend, the AE API is as fast as the native EV API, but your [...]

perl threads kill

use threads; use threads::shared; no warnings ‘threads’; use Net::SMTP; use strict; my $p_status :shared = 0; my $t1 = threads->new( \&check_action ); my $t2 = threads->new( \&time_out ); while(1){ select(undef, undef, undef, 2); if ( $p_status ) { if ($t1->is_joinable()) { $t1->kill(‘KILL’)->detach; }; if ($t2->is_joinable()) { $t2->kill(‘KILL’)->detach; }; last; }; } sub check_action { $SIG{‘KILL’} [...]