From a22dbff21bb1ccb696276c23566ba830421fd3a0 Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Fri, 23 Dec 2011 11:23:15 +0000 Subject: [PATCH] fix disconnect from peer --- perl/DXChannel.pm | 14 ++++++++++---- perl/Msg.pm | 5 +++-- perl/Version.pm | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/perl/DXChannel.pm b/perl/DXChannel.pm index 8fc86495..584a541c 100644 --- a/perl/DXChannel.pm +++ b/perl/DXChannel.pm @@ -147,11 +147,16 @@ sub alloc { my ($pkg, $call, $conn, $user) = @_; my $self = {}; - + die "trying to create a duplicate channel for $call" if $channels{$call}; + bless $self, $pkg; + $self->{call} = $call; $self->{priv} = 0; - $self->{conn} = $conn if defined $conn; # if this isn't defined then it must be a list + if (defined $conn && ref $conn) { # if this isn't defined then it must be a list + $self->{conn} = $conn; + $conn->set_on_eof(sub {$self->disconnect}); + } if (defined $user) { $self->{user} = $user; $self->{lang} = $user->lang; @@ -177,7 +182,6 @@ sub alloc $count++; dbg("DXChannel $self->{call} created ($count)") if isdbg('chan'); - bless $self, $pkg; return $channels{$call} = $self; } @@ -202,7 +206,9 @@ sub rebless { my $self = shift; my $class = shift; - return $channels{$self->{call}} = bless $self, $class; + my $new = bless $self, $class; + $new->{conn}->on_eof(sub {$new->disconnect}); + return $channels{$self->{call}} = $new; } sub rec diff --git a/perl/Msg.pm b/perl/Msg.pm index 35290410..60906c59 100644 --- a/perl/Msg.pm +++ b/perl/Msg.pm @@ -61,11 +61,12 @@ sub set_error $conn->{eproc} = $callback; } -sub set_eof +sub set_on_eof { my $conn = shift; my $callback = shift; - $conn->{sock}->on_eof(sub {$callback}); + $conn->{sock}->on_eof($callback); + $conn->{sock}->on_error($callback); } sub set_rproc diff --git a/perl/Version.pm b/perl/Version.pm index fea0581e..99b2e673 100644 --- a/perl/Version.pm +++ b/perl/Version.pm @@ -11,7 +11,7 @@ use vars qw($version $subversion $build $gitversion); $version = '1.56'; $subversion = '0'; -$build = '7'; -$gitversion = 'a60f14f'; +$build = '8'; +$gitversion = '0702d38'; 1; -- 2.43.0