From 516c9d91086049a9cd77db65df2f03673b536e72 Mon Sep 17 00:00:00 2001 From: Robin Redeker Date: Mon, 4 Aug 2008 15:46:05 +0200 Subject: [PATCH] migration to AnyEvent::Socket --- lib/AnyEvent/HTTPD/HTTPServer.pm | 32 +++++++++++++++++++------------- lib/AnyEvent/HTTPD/Request.pm | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/AnyEvent/HTTPD/HTTPServer.pm b/lib/AnyEvent/HTTPD/HTTPServer.pm index 91e804c..81f37e0 100644 --- a/lib/AnyEvent/HTTPD/HTTPServer.pm +++ b/lib/AnyEvent/HTTPD/HTTPServer.pm @@ -5,7 +5,7 @@ no warnings; use IO::Socket::INET; use Object::Event; use AnyEvent::Handle; -use AnyEvent::Util; +use AnyEvent::Socket; use AnyEvent::HTTPD::HTTPConnection; @@ -48,24 +48,30 @@ sub new { $sock or die "Couldn't create listening socket: $!"; - $self->{lw} = AnyEvent::Util::listen ($sock, sub { - my ($sock) = @_; + tcp_server undef, $self->{port}, sub { + my ($fh) = @_; + unless ($fh) { + $self->event (error => "couldn't accept client: $!"); + return; + } + $self->accept_connection ($fh); + }; - my $htc = AnyEvent::HTTPD::HTTPConnection->new (fh => $sock); - $self->{handles}->{$htc} = $htc; + return $self +} - $htc->reg_cb (disconnect => sub { - delete $self->{handles}->{$_[0]}; - $self->event (disconnect => $_[0]) - }); +sub accept_connection { + my ($self, $fh) = @_; - $self->event (connect => $htc); + my $htc = AnyEvent::HTTPD::HTTPConnection->new (fh => $fh); + $self->{handles}->{$htc} = $htc; - }, sub { - $self->event (error => $!); + $htc->reg_cb (disconnect => sub { + delete $self->{handles}->{$_[0]}; + $self->event (disconnect => $_[0]) }); - return $self + $self->event (connect => $htc); } 1; diff --git a/lib/AnyEvent/HTTPD/Request.pm b/lib/AnyEvent/HTTPD/Request.pm index 048bf72..22be5eb 100644 --- a/lib/AnyEvent/HTTPD/Request.pm +++ b/lib/AnyEvent/HTTPD/Request.pm @@ -84,7 +84,7 @@ This method will send a response to the request. If no C<$res> argument was given eventually accumulated output will be send as C. -Otherweis C<$res> can be: +Otherwise C<$res> can be: =over 4 -- 2.11.4.GIT