Skip to content

Commit

Permalink
shutdown() will unregister all registered sessions now.
Browse files Browse the repository at this point in the history
  • Loading branch information
bingos committed Apr 24, 2006
1 parent b4c879b commit e848864
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ Revision history for Perl extension POE::Component::IRC.
if we spawned it.
- Spotted a problem with register() it was still stashing
POE::Session refs. Bad BinGOs.
- shutdown() will issue a warning if any sessions are still
registered with the component.
- shutdown() will unregister all registered sessions now.

4.85 Thu Apr 13 12:37:49 BST 2006
- Numerous bug fixes to State and Qnet/State which were
Expand Down
14 changes: 13 additions & 1 deletion lib/POE/Component/IRC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1340,13 +1340,13 @@ sub register_session {
# Tell the IRC session to go away.
sub shutdown {
my ($kernel, $self) = @_[KERNEL, OBJECT];
$self->_unregister_sessions();
$kernel->alarm_remove_all();
$kernel->alias_remove( $_ ) for $kernel->alias_list( $_[SESSION] );
delete $self->{$_} for qw(socket sock socketfactory dcc wheelmap);
# Delete all plugins that are loaded.
$self->plugin_del( $_ ) for keys %{ $self->plugin_list() };
$self->{resolver}->shutdown() if $self->{mydns} and $self->{resolver};
warn "Shutdown called while sessions still registered\n" if scalar keys %{ $self->{sessions} };
undef;
}

Expand Down Expand Up @@ -1508,6 +1508,18 @@ sub _unregister {
undef;
}

sub _unregister_sessions {
my $self = shift;
my $poco_id = $self->session_id();
foreach my $session_id ( keys %{ $self->{sessions} } ) {
if (--$self->{sessions}->{$session_id}->{refcnt} <= 0) {
delete $self->{sessions}->{$session_id};
$poe_kernel->refcount_decrement($session_id, PCI_REFCOUNT_TAG)
unless ( $session_id eq $poco_id );
}
}
}

# Asks the IRC server for some random information about particular nicks.
sub userhost {
my ($kernel, @nicks) = @_[KERNEL, ARG0 .. $#_];
Expand Down
3 changes: 3 additions & 0 deletions t/1_new.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ BEGIN { use_ok('POE::Component::IRC') };
#warn "\nThese next tests will hang if you are firewalling localhost interfaces";

#use POE qw(Wheel::SocketFactory Wheel::ReadWrite Filter::Line);

diag( "Testing POE::Component::IRC $POE::Component::IRC::VERSION, Perl $], $^X" );

use POE;

my ($self) = POE::Component::IRC->new('irc-client');
Expand Down
2 changes: 1 addition & 1 deletion t/3_connect.t
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ sub irc_001 {
ok( $poco_object->server_name() eq 'test.script', "Server Name" );
ok( $poco_object->nick_name() eq 'testbot', "Nick Name" );

$self->yield( 'unregister' => 'all' );
#$self->yield( 'unregister' => 'all' );
$self->yield( 'shutdown');
undef;
}

0 comments on commit e848864

Please sign in to comment.