2. Attention for audience
• This slide is mainly written by Japanese, and
few English. In the future, I will write and
share this slide of English version, perhaps.
• I speach by Japanese language.
• If you do not known Japanese language,
please fun and feel from some Perl code
and few English description on this slide.
32. Echo Server (AnyEvent)
#!/usr/bin/env perl
use strict;
use warnings;
use AnyEvent;
use AnyEvent::Socket qw(tcp_server);
use AnyEvent::Handle;
use constant PORT => 9000;
my $cv = AnyEvnet->condvar;
my $echo_server = tcp_server undef, PORT, sub {
my $fh = shift;
my $hdl; $hdl = AnyEvent::Handle->new(
fh => $fh,
on_read => sub {
$hdl->push_write(delete $hdl->{rbuf});
},
);
};
$cv->recv;
35. Apache::Qpsmtpd
package Apache::Qpsmtpd;
use 5.006001;
use strict;
use warnings FATAL => 'all';
use Apache2::ServerUtil ();
use Apache2::Connection ();
use Apache2::Const -compile => qw(OK MODE_GETLINE);
use APR::Const -compile => qw(SO_NONBLOCK EOF SUCCESS);
use APR::Error ();
use APR::Brigade ();
use APR::Bucket ();
use APR::Socket ();
use Apache2::Filter ();
use ModPerl::Util ();
our $VERSION = '0.02';
sub handler {
my Apache2::Connection $c = shift;
$c->client_socket->opt_set(APR::Const::SO_NONBLOCK => 0);
die "$ENV{QPSMTPD_CONFIG} must be given" unless $ENV{QPSMTPD_CONFIG};
my $qpsmtpd = Qpsmtpd::Apache->new();
$qpsmtpd->start_connection(
ip => $c->remote_ip,
host => $c->remote_host,
info => undef,
conn => $c,
);
$qpsmtpd->run($c);
$qpsmtpd->run_hooks("post-connection");
$qpsmtpd->connection->reset;
return Apache2::Const::OK;
}
...