sub init($) {
my ($self) = @_;
+ my ($code, $text);
$self->{'engine'}->{'case'} = $self;
if (${ref($self)."::VCL"}) {
my $vcl = $varnish->backend_block('main') . ${ref($self)."::VCL"};
- $varnish->send_vcl(ref($self), $vcl);
- my ($ev, $resp) = $self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown');
- if ($ev eq 'ev_varnish_command_unknown') {
+ ($code, $text) = $varnish->send_vcl(ref($self), $vcl);
+ if ($code != 200) {
$self->{'failed'} += 1;
- die "Unable to load VCL.\n"
+ die "Unable to load VCL\n";
+ }
+ ($code, $text) = $varnish->use_vcl(ref($self));
+ if ($code != 200) {
+ $self->{'failed'} += 1;
+ die "Unable to load VCL\n";
}
- $varnish->use_vcl(ref($self));
- $self->run_loop('ev_varnish_command_ok');
}
$varnish->set_param('vcl_trace' => 'on');
- $self->run_loop('ev_varnish_command_ok');
# Start the child
- $varnish->start_child();
+ ($code, $text) = $varnish->start_child();
+ if ($code != 200) {
+ $self->{'failed'} += 1;
+ die "Unable to start child\n";
+ }
$self->run_loop('ev_varnish_child_started');
}
# Stop the worker process
$varnish->stop_child();
- # Wait for both events, the order is unpredictable, so wait for
- # any of them both times.
- $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok');
- $self->run_loop('ev_varnish_child_stopped', 'ev_varnish_command_ok');
+ $self->run_loop('ev_varnish_child_stopped');
# Revert to initial VCL script
no strict 'refs';
if (${ref($self)."::VCL"}) {
$varnish->use_vcl('boot');
- $self->run_loop('ev_varnish_command_ok', 'ev_varnish_command_unknown');
+ $self->run_loop('ev_varnish_result');
}
delete $self->{'engine'}->{'case'};
}
}
my $command = join(' ', @args);
+ $self->log("sending command: $command");
$self->{'mux'}->write($self->{'socket'}, $command . "\n");
$self->{'mux'}->set_timeout($self->{'socket'}, 2);
$self->{'pending'} = $command;
+ my ($ev, $code, $text) =
+ $self->{'engine'}->run_loop('ev_varnish_result',
+ 'ev_varnish_timeout');
+ delete $self->{'pending'};
+ return ($code, $text);
}
sub send_vcl($$$) {
my ($self, $config, $vcl) = @_;
- $self->send_command('vcl.inline', $config, $vcl);
+ return $self->send_command('vcl.inline', $config, $vcl);
}
sub use_vcl($$) {
my ($self, $config) = @_;
- $self->send_command('vcl.use', $config);
+ return $self->send_command('vcl.use', $config);
}
sub start_child($) {
die "already started\n"
if $self->{'state'} eq "started";
- $self->send_command("start");
+ return $self->send_command("start");
}
sub stop_child($) {
die "already stopped\n"
if $self->{'state'} eq 'stopped';
- $self->send_command("stop");
+ return $self->send_command("stop");
}
sub set_param($$$) {
my ($self, $param, $value) = @_;
- $self->send_command('param.set', $param, $value);
+ return $self->send_command('param.set', $param, $value);
}
sub shutdown($) {
my $text = substr($$data, length($line), $len);
substr($$data, 0, length($line) + $len + 1, '');
- $self->{'engine'}->ev_varnish_command_ok(delete $self->{'pending'})
- if ($code eq 200 and $self->{'pending'});
-
- $self->{'engine'}->ev_varnish_command_unknown(delete $self->{'pending'})
- if ($code eq 300 and $self->{'pending'});
+ $self->{'engine'}->ev_varnish_result($code, $text);
} else {
if ($$data =~ /^rolling\(2\)\.\.\./m) {
$self->{'state'} = 'stopped';