AnyEvent-HTTPD
view release on metacpan or search on metacpan
lib/AnyEvent/HTTPD/HTTPServer.pm view on Meta::CPAN
It has no public interface yet.
=head1 COPYRIGHT & LICENSE
Copyright 2008-2011 Robin Redeker, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = {
connection_class => "AnyEvent::HTTPD::HTTPConnection",
allowed_methods => [ qw/GET HEAD POST/ ],
@_,
};
bless $self, $class;
my $rself = $self;
weaken $self;
$self->{srv} =
tcp_server $self->{host}, $self->{port}, sub {
my ($fh, $host, $port) = @_;
unless ($fh) {
$self->event (error => "couldn't accept client: $!");
return;
}
$self->accept_connection ($fh, $host, $port);
}, sub {
my ($fh, $host, $port) = @_;
$self->{real_port} = $port;
$self->{real_host} = $host;
return $self->{backlog};
};
return $self
}
sub port { $_[0]->{real_port} }
sub host { $_[0]->{real_host} }
sub allowed_methods { $_[0]->{allowed_methods} }
sub accept_connection {
my ($self, $fh, $h, $p) = @_;
my $htc =
$self->{connection_class}->new (
fh => $fh,
request_timeout => $self->{request_timeout},
allowed_methods => $self->{allowed_methods},
ssl => $self->{ssl},
host => $h,
port => $p);
$self->{handles}->{$htc} = $htc;
weaken $self;
$htc->reg_cb (disconnect => sub {
if (defined $self) {
delete $self->{handles}->{$_[0]};
$self->event (disconnect => $_[0], $_[1]);
}
});
$self->event (connect => $htc);
}
1;
( run in 1.097 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )