Subject: | shutdown |
hei sky, testing this rt thing on cpan.
the problem I was running into is that the component did not provide any way to shut it down. so since it creates a session and increases refcount on it, my daemon would not quit. I've included a patch that adds an event handler used to shut down the component. PODs changed as well.
*** HTTP.pm Fri Oct 4 04:44:48 2002
--- HTTP.pm.orig Fri Oct 4 00:27:43 2002
***************
*** 19,25 ****
use Sys::Hostname qw(hostname);
! $VERSION = 0.03;
use POE::Component::Server::HTTP::Response;
use POE::Component::Server::HTTP::Request;
--- 19,25 ----
use Sys::Hostname qw(hostname);
! $VERSION = 0.02;
use POE::Component::Server::HTTP::Response;
use POE::Component::Server::HTTP::Request;
***************
*** 31,84 ****
"Server" => "POE HTTPD Compontent/$VERSION ($])",
);
sub new {
my $class = shift;
! my $self = bless {@_}, $class;
! $self->{Headers} = { %default_headers,
! ($self->{Headers} ? %{$self->{Headers}}: ())
! };
$self->{TransHandler} = [] unless($self->{TransHandler});
$self->{PreHandler} = {} unless($self->{PreHandler});
$self->{PostHandler} = {} unless($self->{PostHandler});
! if (ref($self->{ContentHandler}) ne 'HASH') {
! croak "You need a default content handler or a ContentHandler setup"
! unless ref($self->{DefaultContentHandler}) eq 'CODE';
$self->{ContentHandler} = {};
$self->{ContentHandler}->{'/'} = $self->{DefaultContentHandler};
}
- $self->{Hostname} = hostname() unless $self->{Hostname};
! my $alias = "PoCo::Server::HTTP::";
! my $session = POE::Session->create(
! inline_states => {
_start => sub {
! $_[KERNEL]->alias_set($alias . $_[SESSION]->ID);
},
_stop => sub {},
- _signal => sub {},
accept => \&accept,
input => \&input,
execute => \&execute,
! shutdown => sub {
! my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
! $kernel->call($alias . "TCP::" . $session->ID, "shutdown");
! $kernel->alias_remove($alias . $session->ID);
! },
! },
! heap => { self => $self }
);
! POE::Component::Server::TCP->new(
! Alias => $alias . "TCP::" . $session->ID,
! Port => $self->{Port},
! Acceptor => sub {
! $poe_kernel->post($session, 'accept', @_[ARG0 .. ARG2]);
! }
! );
! return $session->ID;
! }
sub accept {
my ($socket,$remote_addr, $remote_port) = @_[ARG0,ARG1,ARG2];
--- 31,78 ----
"Server" => "POE HTTPD Compontent/$VERSION ($])",
);
+
+
sub new {
my $class = shift;
! my $self = bless {@_},$class;
! $self->{Headers} = { %default_headers, ($self->{Headers} ? %{$self->{Headers}}: ())};
!
!
$self->{TransHandler} = [] unless($self->{TransHandler});
$self->{PreHandler} = {} unless($self->{PreHandler});
$self->{PostHandler} = {} unless($self->{PostHandler});
! if(ref($self->{ContentHandler}) ne 'HASH') {
! croak "You need a default content handler or a ContentHandler setup" unless(ref($self->{DefaultContentHandler}) eq 'CODE');
$self->{ContentHandler} = {};
$self->{ContentHandler}->{'/'} = $self->{DefaultContentHandler};
}
!
!
! $self->{Hostname} = hostname() unless($self->{Hostname});
!
! my $session = POE::Session->new(
_start => sub {
! $poe_kernel->refcount_increment($_[SESSION]->ID(),"deamon");
! $_[HEAP]->{self} = $self;
},
_stop => sub {},
accept => \&accept,
input => \&input,
execute => \&execute,
! _signal => sub {},
);
! POE::Component::Server::TCP->new( Port => $self->{Port}, Acceptor => sub {
! $poe_kernel->post($session,'accept',@_[ARG0,ARG1,ARG2]);
! });
!
! }
!
!
sub accept {
my ($socket,$remote_addr, $remote_port) = @_[ARG0,ARG1,ARG2];
***************
*** 114,119 ****
--- 108,114 ----
$_[HEAP]->{c}->{$wheel->ID} = $connection
}
+
sub execute {
my $id = $_[ARG0];
my $self = $_[HEAP]->{self};
***************
*** 251,257 ****
use POE::Component::Server::HTTP;
use HTTP::Status;
! $httpd = POE::Component::Server::HTTP->new(
Port => 8000,
ContentHandler => { '/' => \&handler },
Headers => { Server => 'My Server' },
--- 246,252 ----
use POE::Component::Server::HTTP;
use HTTP::Status;
! POE::Component::Server::HTTP->new(
Port => 8000,
ContentHandler => { '/' => \&handler },
Headers => { Server => 'My Server' },
***************
*** 264,271 ****
return RC_OK;
}
- POE::Kernel->call($httpd, "shutdown");
-
=head1 DESCRIPTION
POE::Component::Server::HTTP (PoCo::HTTPD) is a framework for building
--- 259,264 ----
***************
*** 353,364 ****
=back
- =head1 Events
-
- The C<shutdown> event may be sent to the component indicating that it should shut down. The event may be sent using the return value of the I<new()> method (which is a session id) by either post()ing or call()ing.
-
- I've experienced some problems with the session not receiving the event when it gets post()ed so call() is advised.
-
=head1 See Also
Please also take a look at L<HTTP::Response>, L<HTTP::Request>,
--- 346,351 ----
***************
*** 376,383 ****
=item Add more options to streaming
- =item Figure out why post()ed C<shutdown> events don't get received.
-
=item Probably lots of other API changes
=back
--- 363,368 ----