$self->log(sprintf("%d: FAIL: %s: %s",
$self->{'count'}, $method, $@));
}
+ # Make sure all clients have closed their connections.
+ foreach my $client (@{$self->{'engine'}->{'clients'}}) {
+ $client->shutdown;
+ }
+ @{$self->{'engine'}->{'clients'}} = ();
}
$self->{'stop'} = [gettimeofday()];
}
use IO::Socket::INET;
+our $id_seq = 1;
+
sub new($$) {
my ($this, $engine, $attrs) = @_;
my $class = ref($this) || $this;
my $self = bless({ 'engine' => $engine,
'mux' => $engine->{'mux'},
+ 'id' => $id_seq++,
'requests' => 0,
'responses' => 0 }, $class);
+ push(@{$self->{'engine'}->{'clients'}}, $self);
+
return $self;
}
sub log($$;$) {
my ($self, $str, $extra_prefix) = @_;
- $self->{'engine'}->log($self, 'CLI: ' . ($extra_prefix || ''), $str);
+ $self->{'engine'}->log($self, sprintf('CLI[%d]: ', $self->{'id'}) . ($extra_prefix || ''), $str);
}
sub logf($$;@) {
my ($self, $fmt, @args) = @_;
- $self->{'engine'}->log($self, 'CLI: ', sprintf($fmt, @args));
+ $self->{'engine'}->log($self, sprintf('CLI[%d]: ', $self->{'id'}), sprintf($fmt, @args));
}
sub send_request($$;$) {
}
sub shutdown($) {
- my ($self, $how) = @_;
+ my ($self) = @_;
- $self->{'mux'}->close($self->{'fh'});
- $self->{'fh'} = undef;
+ if (defined($self->{'fh'})) {
+ my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'});
+
+ if ($inbuffer ne '') {
+ use Data::Dumper;
+
+ $self->log('Discarding: ' . Dumper(\$inbuffer));
+ $self->{'mux'}->inbuffer($self->{'fh'}, '');
+ }
+
+ $self->{'mux'}->close($self->{'fh'});
+ $self->{'fh'} = undef;
+ }
}
sub mux_input($$$$) {
sub mux_close($$) {
my ($self, $mux, $fh) = @_;
- delete $self->{'fh'};
+ $self->{'fh'} = undef;
}
1;
sub shutdown($) {
my ($self) = @_;
+ my $inbuffer = $self->{'mux'}->inbuffer($self->{'fh'});
+
+ if ($inbuffer ne '') {
+ use Data::Dumper;
+
+ $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper(\$inbuffer));
+ $self->{'mux'}->inbuffer($self->{'fh'}, '');
+ }
+
$self->{'mux'}->close($self->{'fh'});
}
# of request, so if there is anything left in input buffer, it
# must be incomplete because "mux_input" left it there.
- die "Junk or incomplete request\n"
- unless $$data eq '';
+ if ($$data ne '') {
+ use Data::Dumper;
+
+ $self->{'server'}->log('Junk or incomplete request. Discarding: ' . Dumper($data));
+ $$data = '';
+ }
}
1;