{
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;
$count++;
dbg("DXChannel $self->{call} created ($count)") if isdbg('chan');
- bless $self, $pkg;
return $channels{$call} = $self;
}
{
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
$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