From phk at projects.linpro.no Tue Jan 2 13:41:08 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 2 Jan 2007 14:41:08 +0100 (CET) Subject: r1231 - trunk/varnish-cache/bin/varnishd Message-ID: <20070102134108.C936F1EC525@projects.linpro.no> Author: phk Date: 2007-01-02 14:41:08 +0100 (Tue, 02 Jan 2007) New Revision: 1231 Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c trunk/varnish-cache/bin/varnishd/common.h trunk/varnish-cache/bin/varnishd/storage_file.c trunk/varnish-cache/bin/varnishd/varnishd.c Log: Polish as result of flexelint run and record a couple of thoughts. Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pass.c 2006-12-18 15:58:59 UTC (rev 1230) +++ trunk/varnish-cache/bin/varnishd/cache_pass.c 2007-01-02 13:41:08 UTC (rev 1231) @@ -29,6 +29,9 @@ * $Id$ * * XXX: charge bytes to srcaddr + * XXX: buffer to relieve backed ASAP. + * XXX: Check if response has any body + * XXX: Don't pass chunked to HTTP/1.0 client */ #include Modified: trunk/varnish-cache/bin/varnishd/common.h =================================================================== --- trunk/varnish-cache/bin/varnishd/common.h 2006-12-18 15:58:59 UTC (rev 1230) +++ trunk/varnish-cache/bin/varnishd/common.h 2007-01-02 13:41:08 UTC (rev 1231) @@ -46,4 +46,3 @@ int TCP_parse(const char *str, char **addr, char **port); int TCP_open(const char *addr, const char *port, int http); void TCP_check(struct cli *cli, const char *addr, const char *port); - Modified: trunk/varnish-cache/bin/varnishd/storage_file.c =================================================================== --- trunk/varnish-cache/bin/varnishd/storage_file.c 2006-12-18 15:58:59 UTC (rev 1230) +++ trunk/varnish-cache/bin/varnishd/storage_file.c 2007-01-02 13:41:08 UTC (rev 1231) @@ -123,7 +123,7 @@ off_t o; struct stat st; - AN(sc != NULL); + AN(sc); AZ(fstat(sc->fd, &st)); #if defined(HAVE_SYS_STATVFS_H) || defined(HAVE_SYS_VFS_H) Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2006-12-18 15:58:59 UTC (rev 1230) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-01-02 13:41:08 UTC (rev 1231) @@ -216,10 +216,12 @@ switch (sscanf(argv, "%u,%u,%u", &ua, &ub, &uc)) { case 3: params->wthread_timeout = uc; + /* FALLTHROUGH */ case 2: if (ub < ua) usage(); params->wthread_max = ub; + /* FALLTHROUGH */ case 1: if (ua < 1) usage(); @@ -386,6 +388,21 @@ cli[0].result = CLIS_OK; heritage.socket = -1; + + /* + * Set up a temporary param block until VSL_MgtInit() can + * replace with shmem backed structure version. + * + * XXX: I wonder if it would be smarter to inform the child process + * XXX: about param changes via CLI rather than keeping the param + * XXX: block in shared memory. It would give us the advantage + * XXX: of having the CLI thread be able to take action on the + * XXX: change. + * XXX: For now live with the harmless flexelint warning this causes: + * XXX: varnishd.c 393 Info 789: Assigning address of auto variable + * XXX: 'param' to static + */ + memset(¶m, 0, sizeof param); params = ¶m; mgt_vcc_init(); From des at projects.linpro.no Wed Jan 10 13:13:50 2007 From: des at projects.linpro.no (des at projects.linpro.no) Date: Wed, 10 Jan 2007 14:13:50 +0100 (CET) Subject: r1232 - in trunk/varnish-tools: . regress regress/lib regress/lib/Varnish regress/lib/Varnish/Test Message-ID: <20070110131350.6C9791EC9FF@projects.linpro.no> Author: des Date: 2007-01-10 14:13:50 +0100 (Wed, 10 Jan 2007) New Revision: 1232 Added: trunk/varnish-tools/regress/ trunk/varnish-tools/regress/lib/ trunk/varnish-tools/regress/lib/Varnish/ trunk/varnish-tools/regress/lib/Varnish/Test.pm trunk/varnish-tools/regress/lib/Varnish/Test/ trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm trunk/varnish-tools/regress/lib/Varnish/Test/Code.pm trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm trunk/varnish-tools/regress/lib/Varnish/Test/Token.pm trunk/varnish-tools/regress/lib/Varnish/Test/Tokenizer.pm trunk/varnish-tools/regress/test1 trunk/varnish-tools/regress/varnish-regress.pl Log: Unfinished regression test framework which knutroy is taking over from me. Added: trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Accelerator.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,108 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Accelerator; + +use strict; +use base 'Varnish::Test::Object'; +use POSIX; + +sub _init($) { + my $self = shift; + + # Default address / port + $self->vars->{'address'} = 'localhost'; + $self->vars->{'port'} = '8001'; +} + +sub start($) { + my $self = shift; + + my $backend = $self->vars->{'backend'}; + (defined($backend) && + $backend->isa('Varnish::Test::Server')) + or die("invalid server\n"); + + my ($stdinx, $stdin) = POSIX::pipe() + or die("pipe(): $!\n"); + my ($stdout, $stdoutx) = POSIX::pipe() + or die("pipe(): $!\n"); + my ($stderr, $stderrx) = POSIX::pipe() + or die("pipe(): $!\n"); + my $pid = fork(); + if (!defined($pid)) { + # fail + die("fork(): $!\n"); + } elsif ($pid == 0) { + # child + POSIX::dup2($stdinx, 0); + POSIX::close($stdin); + POSIX::close($stdinx); + POSIX::dup2($stdoutx, 1); + POSIX::close($stdout); + POSIX::close($stdoutx); + POSIX::dup2($stderrx, 2); + POSIX::close($stderr); + POSIX::close($stderrx); + # XXX must be in path + exec('varnishd', + '-d', '-d', + '-b', $backend->get('address') . ":" . $backend->get('port')); + exit(1); + } + # parent + $self->{'pid'} = $pid; + $self->{'stdin'} = $stdin; + POSIX::close($stdinx); + $self->{'stdout'} = $stdout; + POSIX::close($stdoutx); + $self->{'stderr'} = $stderr; + POSIX::close($stderrx); +} + +sub stop($) { + my $self = shift; + + POSIX::close($self->{'stdin'}) + if ($self->{'stdin'}); + POSIX::close($self->{'stdout'}) + if ($self->{'stdout'}); + POSIX::close($self->{'stderr'}) + if ($self->{'stderr'}); + sleep(1); + kill(15, $self->{'pid'}) + if ($self->{'pid'}); + delete($self->{'stdin'}); + delete($self->{'stdout'}); + delete($self->{'stderr'}); + delete($self->{'pid'}); +} + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Case.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,36 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Case; + +use strict; +use base 'Varnish::Test::Object'; + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Client.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,55 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Client; + +use strict; +use base 'Varnish::Test::Object'; +use IO::Socket; +use URI; + +sub request($$$) { + my $self = shift; + my $server = shift; + my $url = shift; + + (defined($server) && + ($server->isa('Varnish::Test::Accelerator') || + $server->isa('Varnish::Test::Server'))) + or die("invalid server\n"); + $url = URI->new($url) + or die("invalid URL\n"); + + # GET $uri->path_query HTTP/$self->{'protocol'} + # Host: $uri->host_port + # Connection: xxx +} + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Code.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Code.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Code.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,67 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Code; + +use strict; + +sub new($$$) { + my $this = shift; + my $class = ref($this) || $this; + my $context = shift; + + my $self = { + 'context' => $context, + }; + bless($self, $class); + + $self->_parse(shift) + if (@_); + + return $self; +} + +sub _parse($$) { + my $self = shift; + my $t = shift; + + print STDERR "\t"; + while (!$t->peek()->is("SemiColon")) { + print STDERR " " . $t->peek()->value(); + $t->shift(); + } + $t->shift("SemiColon"); + print STDERR ";\n"; +} + +sub run($) { +} + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Context.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,122 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Context; + +use strict; + +# +# A Context is an object that has a name, a type, and a set of named +# variables and procedures associated with it. A context may have a +# parent, from which it inherits variables and procedures. +# + +sub new($;$) { + my $this = shift; + my $class = ref($this) || $this; + my $parent = shift; + + my $self = { + 'parent' => $parent, + 'vars' => { }, + 'procs' => { }, + }; + bless($self, $class); + + return $self; +} + +sub parent($) { + my $self = shift; + + return $self->{'parent'}; +} + +sub vars($) { + my $self = shift; + + return $self->{'vars'}; +} + +sub procs($) { + my $self = shift; + + return $self->{'procs'}; +} + +sub set($$$) { + my $self = shift; + my $key = shift; + my $value = shift; + + if (!exists($self->vars->{$key}) && + $self->parent && $self->parent->has($key)) { + $self->parent->set($key, $value); + } else { + $self->vars->{$key} = $value; + } + return $value; +} + +sub has($$) { + my $self = shift; + my $key = shift; + + return exists($self->{'vars'}->{$key}) || + $self->parent->has($key); +} + +sub get($$) { + my $self = shift; + my $key = shift; + + return exists($self->vars->{$key}) ? $self->vars->{$key} : + ($self->parent && $self->parent->get($key)); +} + +sub type($) { + my $self = shift; + + if (!defined($self->{'type'})) { + ($self->{'type'} = ref($self)) =~ s/^(\w+::)*(\w+)$/$2/; + print STDERR "$self->{'type'}\n"; + } + return $self->{'type'}; +} + +sub name($;$) { + my $self = shift; + + $self->{'name'} = shift + if (@_); + return $self->{'name'}; +} + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Object.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,82 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Object; + +use strict; +use base 'Varnish::Test::Context'; +use Varnish::Test::Code; + +sub new($$;$) { + my $this = shift; + my $class = ref($this) || $this; + my $parent = shift; + + my $self = Varnish::Test::Context->new($parent); + $self->{'code'} = []; + bless($self, $class); + + $self->_init(); + + $self->_parse($_[0]) + if (@_); + + return $self; +} + +sub _init($) { + my $self = shift; + + # nothing +} + +sub _parse($$) { + my $self = shift; + my $t = shift; + + $t->shift_keyword(lc($self->type)); + $self->name($t->shift("Identifier")->value); + $t->shift("LeftBrace"); + while (!$t->peek()->is("RightBrace")) { + push(@{$self->{'code'}}, Varnish::Test::Code->new($self, $t)); +# $token = $t->shift("Identifier"); +# my $key = $token->value; +# $token = $t->shift("Assign"); +# $token = $t->shift("Integer", "Real", "String"); +# my $value = $token->value; +# $token = $t->shift("SemiColon"); +# $t->warn("multiple assignments to $self->{'name'}.$key") +# if ($self->has($key)); +# $self->set($key, $value); + } + $t->shift("RightBrace"); +} + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Request.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,36 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Request; + +use strict; +use base 'Varnish::Test::Object'; + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Response.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,36 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Response; + +use strict; +use base 'Varnish::Test::Object'; + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Server.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,43 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Server; + +use strict; +use base 'Varnish::Test::Object'; + +sub _init($) { + my $self = shift; + + $self->vars->{'address'} = 'localhost'; + $self->vars->{'port'} = '9001'; +} + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Token.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Token.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Token.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,168 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Token; + +use strict; + +# Common constructor +sub new { + my $this = shift; + my $class = ref($this) || $this; + my $pos = shift; + + my $self = { + 'pos' => $pos, + 'value' => '???', + }; + bless($self, $class); + + # hack: use eval to avoid clobbering @_ + eval { ($self->{'type'} = $class) =~ s/^(\w+::)*(\w+)$/$2/; }; + + $self->init(@_); + + return $self; +} + +# Default initializer +sub init($;$) { + my $self = shift; + + $self->value(@_); +} + +sub type($;$) { + my $self = shift; + + $self->{'type'} = shift + if (@_); + return $self->{'type'}; +} + +sub value($;$) { + my $self = shift; + + $self->{'value'} = shift + if (@_); + return $self->{'value'}; +} + +sub is($$) { + my $self = shift; + my $type = shift; + + return ($self->{'type'} eq $type); +} + +sub equals($$) { + my $self = shift; + my $other = shift; + + return ($self->type() eq $other->type() && + $self->value() eq $other->value()); +} + +package Varnish::Test::Token::Assign; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::Comma; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::Compare; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::EOF; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::Identifier; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::Integer; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::Keyword; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::LeftBrace; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::LeftParen; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::Period; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::Real; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::RightBrace; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::RightParen; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::SemiColon; + +use strict; +use base 'Varnish::Test::Token'; + +package Varnish::Test::Token::String; + +use strict; +use base 'Varnish::Test::Token'; + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test/Tokenizer.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test/Tokenizer.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test/Tokenizer.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,185 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test::Tokenizer; + +use strict; +use Varnish::Test::Token; + +sub new($$) { + my $this = shift; + my $class = ref($this) || $this; + + my $self = {}; + bless($self, $class); + $self->tokenize($_[0]) + if (@_); + + return $self; +} + +sub tokenize($$) { + my $self = shift; + my $fn = shift; + + local *FILE; + local $/; + + $self->{'fn'} = $fn; + $self->{'tokens'} = (); + + open(FILE, "<", $self->{'fn'}) + or die("$self->{'fn'}: $!\n"); + my $spec = ; + close(FILE); + + # tokenize + my @tokens = (); + for (;;) { + my $type = undef; + if ($spec =~ m/\G\s*$/gc) { + # EOF + push(@tokens, Varnish::Test::Token::EOF->new(pos($spec))); + last; + } elsif ($spec =~ m/\G\s*(\*\/\*([^\*]|\*[^\/])+\*\/)/gc) { + # multiline comment + } elsif ($spec =~ m/\G\s*((?:\/\/|\#).*?)\n/gc) { + # single-line comment + } elsif ($spec =~ m/\G\s*\b(\d+\.\d+)\b/gc) { + # real literal + push(@tokens, Varnish::Test::Token::Real->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*\b(\d+)\b/gc) { + # integer literal + push(@tokens, Varnish::Test::Token::Integer->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*\"((?:\\.|[^\"])*)\"/gc) { + # string literal + push(@tokens, Varnish::Test::Token::String->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*\b(accelerator|client|init|server|case|test|ticket)\b/gc) { + # keyword + push(@tokens, Varnish::Test::Token::Keyword->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*\b(\w+)\b/gc) { + # identifier + push(@tokens, Varnish::Test::Token::Identifier->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*(\{)/gc) { + # opening brace + push(@tokens, Varnish::Test::Token::LeftBrace->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*(\})/gc) { + # closing brace + push(@tokens, Varnish::Test::Token::RightBrace->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*(\()/gc) { + # opening paren + push(@tokens, Varnish::Test::Token::LeftParen->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*(\))/gc) { + # closing paren + push(@tokens, Varnish::Test::Token::RightParen->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*(\;)/gc) { + # semicolon + push(@tokens, Varnish::Test::Token::SemiColon->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*(\.)/gc) { + # period + push(@tokens, Varnish::Test::Token::Period->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*(\,)/gc) { + # comma + push(@tokens, Varnish::Test::Token::Comma->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*([\<\>\=\!]=)/gc) { + # comparison operator + push(@tokens, Varnish::Test::Token::Compare->new(pos($spec), $1)); + } elsif ($spec =~ m/\G\s*([\+\-\*\/]?=)/gc) { + # assignment operator + push(@tokens, Varnish::Test::Token::Assign->new(pos($spec), $1)); +# } elsif ($spec =~ m/\G\s*([\+\-\*\/])/gc) { +# # arithmetic operator +# push(@tokens, Varnish::Test::Token::ArOp->new(pos($spec), $1)); + } else { + die "$self->{'fn'}: syntax error\n" . substr($spec, pos($spec)) . "\n"; + } + } + + $self->{'tokens'} = \@tokens; + return @tokens; +} + +sub die($$) { + my $self = shift; + my $msg = shift; + + CORE::die("$self->{'fn'}: $msg\n"); +} + +sub warn($$) { + my $self = shift; + my $msg = shift; + + CORE::warn("$self->{'fn'}: $msg\n"); +} + + +# Return the next token from the input queue, but do not remove it +# from the queue. Fatal if the queue is empty. +sub peek($) { + my $self = shift; + + $self->die("premature end of input") + unless @{$self->{'tokens'}}; + return $self->{'tokens'}->[0]; +} + +# Remove the next token from the input queue and return it. +# Additional (optional) arguments are token types which the next token +# must match. Fatal if the queue is empty, or arguments were provided +# but none matched. +sub shift($;@) { + my $self = CORE::shift; + my @expect = @_; + + $self->die("premature end of input") + unless @{$self->{'tokens'}}; + my $token = shift @{$self->{'tokens'}}; + if (@expect) { + return $token + if grep({ $token->is($_) } @expect); + $self->die("expected " . join(", ", @expect) . ", got " . $token->type); + } + return $token; +} + +# As shift(), but next token must be a keyword and the arguments are +# matched against the token's value rather than its type. +sub shift_keyword($@) { + my $self = CORE::shift; + my @expect = @_; + + my $token = $self->shift("Keyword"); + return $token + if grep({ $token->value eq $_ } @expect); + $self->die("expected " . join(", ", @expect) . ", got " . $token->value); +} + +1; Added: trunk/varnish-tools/regress/lib/Varnish/Test.pm =================================================================== --- trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/lib/Varnish/Test.pm 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,114 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +package Varnish::Test; + +use strict; +use base 'Varnish::Test::Context'; +use Varnish::Test::Accelerator; +use Varnish::Test::Case; +use Varnish::Test::Client; +use Varnish::Test::Server; +use Varnish::Test::Tokenizer; + +sub new($;$) { + my $this = shift; + my $class = ref($this) || $this; + + my $self = Varnish::Test::Context->new(); + bless($self, $class); + $self->parse($_[0]) + if (@_); + + return $self; +} + +sub _parse_ticket($$) { + my $self = shift; + my $t = shift; + + $t->shift_keyword("ticket"); + push(@{$self->{'ticket'}}, $t->shift("Integer")); + $t->shift("SemiColon"); +} + +sub _parse_test($$) { + my $self = shift; + my $t = shift; + + my $token = $t->shift_keyword("test"); + $token = $t->shift("String"); + $self->{'descr'} = $token->value; + $token = $t->shift("LeftBrace"); + for (;;) { + $token = $t->peek(); + last if $token->is("RightBrace"); + if (!$token->is("Keyword")) { + $t->die("expected keyword, got " . ref($token)); + } elsif ($token->value eq 'ticket') { + $self->_parse_ticket($t); + } elsif ($token->value eq 'accelerator') { + my $x = Varnish::Test::Accelerator->new($self, $t); + $t->die("duplicate declaration of " . $x->name) + if exists($self->{'vars'}->{$x->name}); + $self->set($x->name, $x); + } elsif ($token->value eq 'client') { + my $x = Varnish::Test::Client->new($self, $t); + $t->die("duplicate declaration of " . $x->name) + if exists($self->{'vars'}->{$x->name}); + $self->set($x->name, $x); + } elsif ($token->value eq 'server') { + my $x = Varnish::Test::Server->new($self, $t); + $t->die("duplicate declaration of " . $x->name) + if exists($self->{'vars'}->{$x->name}); + $self->set($x->name, $x); + } elsif ($token->value eq 'case') { + my $x = Varnish::Test::Case->new($self, $t); + } else { + $t->die("unexpected keyword " . $token->value); + } + } + $token = $t->shift("RightBrace"); +} + +sub parse($$) { + my $self = shift; + my $fn = shift; + + my $t = Varnish::Test::Tokenizer->new($fn); + $self->_parse_test($t); +} + +sub run($) { + my $self = shift; + +} + +1; Added: trunk/varnish-tools/regress/test1 =================================================================== --- trunk/varnish-tools/regress/test1 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/test1 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,51 @@ +test "Preserve HTTP protocol version in PASS mode" { + ticket 56; + + client c1 { + } + + server s1 { + data = "This is a test."; + } + + accelerator a1 { + backend = s1; + vcl = " +sub vcl_recv { + pass; +} +"; + } + + case c10_s10 { + comment = "client 1.0, server 1.0"; + c1.protocol = "1.0"; + s1.protocol = "1.0"; + c1.request(a1, "http://www.example.com/"); + assert(c1.response.protocol == "1.0"); + } + + case c10_s11 { + comment = "client 1.0, server 1.1"; + c1.protocol = "1.0"; + s1.protocol = "1.1"; + c1.request(a1, "http://www.example.com/"); + assert(c1.response.protocol == "1.0"); + } + + case c11_s10 { + comment = "client 1.1, server 1.0"; + c1.protocol = "1.1"; + s1.protocol = "1.0"; + c1.request(a1, "http://www.example.com/"); + assert(c1.response.protocol == "1.1"); + } + + case c11_s11 { + comment = "client 1.1, server 1.1"; + c1.protocol = "1.1"; + s1.protocol = "1.1"; + c1.request(a1, "http://www.example.com/"); + assert(c1.response.protocol == "1.1"); + } +} Added: trunk/varnish-tools/regress/varnish-regress.pl =================================================================== --- trunk/varnish-tools/regress/varnish-regress.pl 2007-01-02 13:41:08 UTC (rev 1231) +++ trunk/varnish-tools/regress/varnish-regress.pl 2007-01-10 13:13:50 UTC (rev 1232) @@ -0,0 +1,39 @@ +#!/usr/bin/perl -Tw +#- +# Copyright (c) 2006 Linpro AS +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer +# in this position and unchanged. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +use strict; +use lib './lib'; +use Varnish::Test; +use Data::Dumper; + +MAIN:{ + my $test = Varnish::Test->new($ARGV[0]); + #print STDERR Dumper($test); +} Property changes on: trunk/varnish-tools/regress/varnish-regress.pl ___________________________________________________________________ Name: svn:executable + * From phk at projects.linpro.no Mon Jan 22 08:43:30 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 22 Jan 2007 09:43:30 +0100 (CET) Subject: r1233 - trunk/varnish-cache Message-ID: <20070122084330.72F351EC3FF@projects.linpro.no> Author: phk Date: 2007-01-22 09:43:30 +0100 (Mon, 22 Jan 2007) New Revision: 1233 Modified: trunk/varnish-cache/autogen.sh Log: Allow automake version 1.10 Modified: trunk/varnish-cache/autogen.sh =================================================================== --- trunk/varnish-cache/autogen.sh 2007-01-10 13:13:50 UTC (rev 1232) +++ trunk/varnish-cache/autogen.sh 2007-01-22 08:43:30 UTC (rev 1233) @@ -15,13 +15,13 @@ exit 1 else case $automake_version in - 1.9*|[23456789].*) - ;; - *) + 0.*|1.[0-8]) echo "your version of automake ($automake_version) is too old;" \ "you need 1.9 or newer." exit 1 ;; + *) + ;; esac fi From phk at projects.linpro.no Mon Jan 22 11:15:27 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 22 Jan 2007 12:15:27 +0100 (CET) Subject: r1234 - trunk/varnish-cache/bin/varnishd Message-ID: <20070122111527.765F51EC401@projects.linpro.no> Author: phk Date: 2007-01-22 12:15:27 +0100 (Mon, 22 Jan 2007) New Revision: 1234 Modified: trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/varnishd.c Log: Make params volatile so changes are discovered. Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2007-01-22 08:43:30 UTC (rev 1233) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2007-01-22 11:15:27 UTC (rev 1234) @@ -104,7 +104,7 @@ unsigned client_http11; }; -extern struct params *params; +extern volatile struct params *params; extern struct heritage heritage; void child_main(void); Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-01-22 08:43:30 UTC (rev 1233) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-01-22 11:15:27 UTC (rev 1234) @@ -60,7 +60,7 @@ #endif struct heritage heritage; -struct params *params; +volatile struct params *params; /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Mon Jan 22 11:15:57 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 22 Jan 2007 12:15:57 +0100 (CET) Subject: r1235 - trunk/varnish-cache/bin/varnishd Message-ID: <20070122111557.975B21EC404@projects.linpro.no> Author: phk Date: 2007-01-22 12:15:57 +0100 (Mon, 22 Jan 2007) New Revision: 1235 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c Log: Cache the workspace size from params so it doesn't change under us. Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-01-22 11:15:27 UTC (rev 1234) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-01-22 11:15:57 UTC (rev 1235) @@ -64,9 +64,10 @@ vbe_new_conn(void) { struct vbe_conn *vbc; - unsigned char *p; + unsigned char *p, space; - vbc = calloc(sizeof *vbc + params->mem_workspace * 2, 1); + space = params->mem_workspace; + vbc = calloc(sizeof *vbc + space * 2, 1); if (vbc == NULL) return (NULL); VSL_stats->n_vbe_conn++; @@ -75,9 +76,9 @@ vbc->http2 = &vbc->http_mem[1]; vbc->fd = -1; p = (void *)(vbc + 1); - http_Setup(vbc->http, p, params->mem_workspace); - p += params->mem_workspace; - http_Setup(vbc->http2, p, params->mem_workspace); + http_Setup(vbc->http, p, space); + p += space; + http_Setup(vbc->http2, p, space); return (vbc); } From phk at projects.linpro.no Mon Jan 22 11:46:25 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 22 Jan 2007 12:46:25 +0100 (CET) Subject: r1236 - trunk/varnish-cache/bin/varnishd Message-ID: <20070122114625.94A9A1EC532@projects.linpro.no> Author: phk Date: 2007-01-22 12:46:25 +0100 (Mon, 22 Jan 2007) New Revision: 1236 Modified: trunk/varnish-cache/bin/varnishd/shmlog.c Log: Use struct assignment to overcome volatile poisoning. Modified: trunk/varnish-cache/bin/varnishd/shmlog.c =================================================================== --- trunk/varnish-cache/bin/varnishd/shmlog.c 2007-01-22 11:15:57 UTC (rev 1235) +++ trunk/varnish-cache/bin/varnishd/shmlog.c 2007-01-22 11:46:25 UTC (rev 1236) @@ -365,6 +365,6 @@ xxxassert(loghead != MAP_FAILED); VSL_stats = &loghead->stats; pp = (void *)(loghead + 1); - memcpy(pp, params, sizeof *pp); + *pp = *params; params = pp; } From phk at projects.linpro.no Mon Jan 22 12:31:53 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 22 Jan 2007 13:31:53 +0100 (CET) Subject: r1237 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20070122123153.1E02E1EC404@projects.linpro.no> Author: phk Date: 2007-01-22 13:31:52 +0100 (Mon, 22 Jan 2007) New Revision: 1237 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt_obj.h trunk/varnish-cache/lib/libvcl/flint.lnt trunk/varnish-cache/lib/libvcl/vcc_compile.c trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl trunk/varnish-cache/lib/libvcl/vcc_obj.c Log: The getaddrinfo(3) API does not tell us the TTL value learned from DNS so we have to add our own stuff for that. Without some kind of TTL, we would hit the DNS server once per failed attempt to connect to the backend. If the backend were down, we could hit it a LOT. In the VCL code: backend foobar { [...] set backend.dnsttl = 20s; } will assign a TTL for DNS lookups of this backends hostname+port combination, we will not hit the DNS server more often that this. The default is set at 30 seconds, short enough to make things are workable in a load-balancing-via-DNS setups, yet long enough to not pound the DNS server flat in case of backend failures. NOTE that as long as we succeed in connecting to the backend we do not perform new DNS lookups. That will have to be revisited along with possible load-balancing schemes for the backend(s). Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/bin/varnishd/cache.h 2007-01-22 12:31:52 UTC (rev 1237) @@ -302,6 +302,9 @@ struct addrinfo *last_addr; TAILQ_HEAD(,vbe_conn) connlist; + + double dnsttl; + double dnstime; #if 0 double responsetime; double timeout; Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-01-22 12:31:52 UTC (rev 1237) @@ -59,12 +59,25 @@ static MTX vbemtx; /*--------------------------------------------------------------------*/ +/* XXX: belongs a more general place */ +static double +Uptime(void) +{ + struct timespec ts; + + assert(clock_gettime(CLOCK_MONOTONIC, &ts) == 0); + return (ts.tv_sec + ts.tv_nsec * 1e-9); +} + +/*--------------------------------------------------------------------*/ + static struct vbe_conn * vbe_new_conn(void) { struct vbe_conn *vbc; - unsigned char *p, space; + unsigned char *p; + unsigned space; space = params->mem_workspace; vbc = calloc(sizeof *vbc + space * 2, 1); @@ -93,6 +106,7 @@ if (bp->addr != NULL) { freeaddrinfo(bp->addr); bp->addr = NULL; + bp->last_addr = NULL; } memset(&hint, 0, sizeof hint); @@ -102,13 +116,14 @@ error = getaddrinfo(bp->hostname, bp->portname == NULL ? "http" : bp->portname, &hint, &res); + bp->dnstime = Uptime(); if (error) { if (res != NULL) freeaddrinfo(res); printf("getaddrinfo: %s\n", gai_strerror(error)); /* XXX */ - bp->addr = NULL; return; } + bp->last_addr = res; bp->addr = res; } @@ -120,9 +135,7 @@ int s; s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (s < 0) - return (s); - else if (connect(s, ai->ai_addr, ai->ai_addrlen)) { + if (s >= 0 && connect(s, ai->ai_addr, ai->ai_addrlen)) { AZ(close(s)); s = -1; } @@ -157,6 +170,9 @@ } } + if (bp->dnstime + bp->dnsttl >= Uptime()) + return (-1); + /* Then do another lookup to catch DNS changes */ vbe_lookup(bp); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-01-22 12:31:52 UTC (rev 1237) @@ -124,6 +124,7 @@ cp->backend[i] = calloc(sizeof *cp->backend[i], 1); XXXAN(cp->backend[i]); cp->backend[i]->magic = BACKEND_MAGIC; + cp->backend[i]->dnsttl = 30; TAILQ_INIT(&cp->backend[i]->connlist); } } @@ -160,6 +161,7 @@ VBACKEND(const char *, host, hostname) VBACKEND(const char *, port, portname) +VBACKEND(double, dnsttl, dnsttl) /*-------------------------------------------------------------------- * XXX: Working relative to t_req is maybe not the right thing, we could Modified: trunk/varnish-cache/include/vrt_obj.h =================================================================== --- trunk/varnish-cache/include/vrt_obj.h 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/include/vrt_obj.h 2007-01-22 12:31:52 UTC (rev 1237) @@ -10,6 +10,8 @@ void VRT_l_backend_host(struct backend *, const char *); const char * VRT_r_backend_port(struct backend *); void VRT_l_backend_port(struct backend *, const char *); +double VRT_r_backend_dnsttl(struct backend *); +void VRT_l_backend_dnsttl(struct backend *, double); const unsigned char * VRT_r_client_ip(struct sess *); void VRT_l_client_ip(struct sess *, const unsigned char *); const char * VRT_r_req_request(struct sess *); Modified: trunk/varnish-cache/lib/libvcl/flint.lnt =================================================================== --- trunk/varnish-cache/lib/libvcl/flint.lnt 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/lib/libvcl/flint.lnt 2007-01-22 12:31:52 UTC (rev 1237) @@ -6,6 +6,7 @@ -printf_code( ju, long long unsigned) -printf_code( jx, long long unsigned) ++libh ../../config.h -header(../../config.h) -sem(lbv_assert, r_no) -sem(strchr, 1p, type(1), 2n == 0 ? (@p < 1p) : (@p < 1p || @p == 0 )) Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/lib/libvcl/vcc_compile.c 2007-01-22 12:31:52 UTC (rev 1237) @@ -258,6 +258,7 @@ t->e = strchr(s, '\0'); t->tok = METHOD; AddRef(tl, t, type); + /* XXX: possibly leaking t */ } void @@ -931,6 +932,7 @@ static void Backend(struct tokenlist *tl) { + unsigned a; struct var *vp; struct token *t_be = NULL; struct token *t_host = NULL; @@ -984,6 +986,27 @@ Fc(tl, 0, ");\n"); vcc_NextToken(tl); break; +#if 0 + case INT: + case SIZE: + case RATE: + case FLOAT: +#endif + case TIME: + Fc(tl, 1, "\t%s ", vp->lname); + a = tl->t->tok; + if (a == T_MUL || a == T_DIV) + Fc(tl, 0, "%g", DoubleVal(tl)); + else if (vp->fmt == TIME) + TimeVal(tl); + else if (vp->fmt == SIZE) + SizeVal(tl); + else if (vp->fmt == RATE) + RateVal(tl); + else + Fc(tl, 0, "%g", DoubleVal(tl)); + Fc(tl, 0, ");\n"); + break; default: vsb_printf(tl->sb, "Assignments not possible for '%s'\n", vp->name); Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl 2007-01-22 12:31:52 UTC (rev 1237) @@ -32,24 +32,25 @@ # Objects which operate on backends set beobj { - { backend.host HOSTNAME } - { backend.port PORTNAME } + { backend.host HOSTNAME } + { backend.port PORTNAME } + { backend.dnsttl TIME } } # Objects which operate on sessions set spobj { - { client.ip IP } - { req.request STRING } - { req.host STRING } - { req.url STRING } - { req.proto STRING } - { req.backend BACKEND } - { obj.valid BOOL } - { obj.cacheable BOOL } - { obj.ttl TIME } - { req.http. HEADER } - { resp.http. HEADER } + { client.ip IP } + { req.request STRING } + { req.host STRING } + { req.url STRING } + { req.proto STRING } + { req.backend BACKEND } + { obj.valid BOOL } + { obj.cacheable BOOL } + { obj.ttl TIME } + { req.http. HEADER } + { resp.http. HEADER } } set tt(IP) "const unsigned char *" Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-01-22 11:46:25 UTC (rev 1236) +++ trunk/varnish-cache/lib/libvcl/vcc_obj.c 2007-01-22 12:31:52 UTC (rev 1237) @@ -18,6 +18,10 @@ "VRT_r_backend_port(backend)", "VRT_l_backend_port(backend, ", }, + { "backend.dnsttl", TIME, 14, + "VRT_r_backend_dnsttl(backend)", + "VRT_l_backend_dnsttl(backend, ", + }, { NULL } }; @@ -82,6 +86,8 @@ "void VRT_l_backend_host(struct backend *, const char *);\n" "const char * VRT_r_backend_port(struct backend *);\n" "void VRT_l_backend_port(struct backend *, const char *);\n" + "double VRT_r_backend_dnsttl(struct backend *);\n" + "void VRT_l_backend_dnsttl(struct backend *, double);\n" "const unsigned char * VRT_r_client_ip(struct sess *);\n" "void VRT_l_client_ip(struct sess *, const unsigned char *);\n" "const char * VRT_r_req_request(struct sess *);\n" From phk at projects.linpro.no Mon Jan 22 13:24:42 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 22 Jan 2007 14:24:42 +0100 (CET) Subject: r1238 - trunk/varnish-cache/bin/varnishd Message-ID: <20070122132442.B75971EC403@projects.linpro.no> Author: phk Date: 2007-01-22 14:24:42 +0100 (Mon, 22 Jan 2007) New Revision: 1238 Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Expend a lock on keeping the backend statistics consistent. Rename the fields to make more sense Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-01-22 12:31:52 UTC (rev 1237) +++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2007-01-22 13:24:42 UTC (rev 1238) @@ -214,9 +214,12 @@ /* Get a backend connection ------------------------------------------ * - * First locate the backend shadow, if necessary by creating one. - * If there are free connections, use the first, otherwise build a - * new connection. + * Try all cached backend connections for this backend, and use the + * first one that is looks like it is still connected. + * If that fails to get us a connection, create a new one, reusing a + * connection from the freelist, if possible. + * + * This function is slightly complicated by optimizations on vbemtx. */ static struct vbe_conn * @@ -225,20 +228,17 @@ struct vbe_conn *vc, *vc2; struct pollfd pfd; struct backend *bp; + int reuse = 0; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); bp = sp->backend; CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); + vc2 = NULL; while (1) { - /* - * Try all connections on this backend until we find one - * that works. If that fails, grab a free connection - * (if any) while we have the lock anyway. - */ - vc2 = NULL; LOCK(&vbemtx); vc = TAILQ_FIRST(&bp->connlist); if (vc != NULL) { + assert(vc->backend == bp); assert(vc->fd >= 0); TAILQ_REMOVE(&bp->connlist, vc, list); } else { @@ -256,8 +256,10 @@ pfd.fd = vc->fd; pfd.events = POLLIN; pfd.revents = 0; - if (!poll(&pfd, 1, 0)) + if (!poll(&pfd, 1, 0)) { + reuse = 1; break; + } VBE_ClosedFd(sp->wrk, vc, 0); } @@ -266,34 +268,33 @@ vc = vbe_new_conn(); else vc = vc2; - AN(vc); - assert(vc->fd == -1); - AZ(vc->backend); + if (vc != NULL) { + assert(vc->fd == -1); + AZ(vc->backend); + vc->fd = vbe_connect(sp, bp); + if (vc->fd < 0) { + LOCK(&vbemtx); + TAILQ_INSERT_HEAD(&vbe_head, vc, list); + VSL_stats->backend_unused++; + UNLOCK(&vbemtx); + vc = NULL; + } else { + vc->backend = bp; + } + } } - - /* If not connected yet, do so */ - if (vc->fd < 0) { - AZ(vc->backend); - vc->fd = vbe_connect(sp, bp); - LOCK(&vbemtx); - if (vc->fd < 0) { - vc->backend = NULL; - TAILQ_INSERT_HEAD(&vbe_head, vc, list); - VSL_stats->backend_unused++; - vc = NULL; - } else { - vc->backend = bp; - } - UNLOCK(&vbemtx); + LOCK(&vbemtx); + if (vc != NULL ) { + VSL_stats->backend_reuse += reuse; + VSL_stats->backend_conn++; } else { - assert(vc->fd >= 0); - assert(vc->backend == bp); + VSL_stats->backend_fail++; } + UNLOCK(&vbemtx); if (vc != NULL ) { + WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); assert(vc->fd >= 0); - VSL_stats->backend_conn++; - WSL(sp->wrk, SLT_BackendXID, vc->fd, "%u", sp->xid); - AN(vc->backend); + assert(vc->backend == bp); } return (vc); } @@ -348,9 +349,9 @@ CHECK_OBJ_NOTNULL(vc, VBE_CONN_MAGIC); assert(vc->fd >= 0); AN(vc->backend); - VSL_stats->backend_recycle++; WSL(w, SLT_BackendReuse, vc->fd, "%s", vc->backend->vcl_name); LOCK(&vbemtx); + VSL_stats->backend_recycle++; TAILQ_INSERT_HEAD(&vc->backend->connlist, vc, list); UNLOCK(&vbemtx); } Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-01-22 12:31:52 UTC (rev 1237) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2007-01-22 13:24:42 UTC (rev 1238) @@ -133,13 +133,14 @@ VRT_free_backends(struct VCL_conf *cp) { - (void)cp; + (void)cp; /* XXX */ } void VRT_fini_backend(struct backend *be) { - (void)be; + + (void)be; /* XXX */ } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Mon Jan 29 22:06:34 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 29 Jan 2007 23:06:34 +0100 (CET) Subject: r1239 - trunk/varnish-cache/bin/varnishd Message-ID: <20070129220634.0F59B1ECA2A@projects.linpro.no> Author: phk Date: 2007-01-29 23:06:33 +0100 (Mon, 29 Jan 2007) New Revision: 1239 Modified: trunk/varnish-cache/bin/varnishd/varnishd.c Log: Things you didn't know about C, #7212: There is no sane way to get sscanf to tell you how many characters were consumed, if you want to allow a variable number of arguments. The special format %n is patently useless for this, because you have to insert it at every conceiveable point in the string and that presumes full explicit whitespace markup. Parse -w argument "by hand", to catch illegal input like "1,INF,15" Tripped over by: Stein Ove Rosseland Fixes: ticket #82 Modified: trunk/varnish-cache/bin/varnishd/varnishd.c =================================================================== --- trunk/varnish-cache/bin/varnishd/varnishd.c 2007-01-22 13:24:42 UTC (rev 1238) +++ trunk/varnish-cache/bin/varnishd/varnishd.c 2007-01-29 22:06:33 UTC (rev 1239) @@ -32,6 +32,7 @@ */ #include +#include #include #include #include @@ -211,25 +212,47 @@ static void tackle_warg(const char *argv) { - unsigned int ua, ub, uc; + unsigned int u; + char *ep, *eq; - switch (sscanf(argv, "%u,%u,%u", &ua, &ub, &uc)) { - case 3: - params->wthread_timeout = uc; - /* FALLTHROUGH */ - case 2: - if (ub < ua) - usage(); - params->wthread_max = ub; - /* FALLTHROUGH */ - case 1: - if (ua < 1) - usage(); - params->wthread_min = ua; - break; - default: + u = strtoul(argv, &ep, 0); + if (ep == argv) usage(); + while (isspace(*ep)) + ep++; + if (u < 1) + usage(); + params->wthread_min = u; + + if (*ep == '\0') { + params->wthread_max = params->wthread_min; + return; } + + if (*ep != ',') + usage(); + u = strtoul(++ep, &eq, 0); + if (eq == ep) + usage(); + if (u < params->wthread_min) + usage(); + while (isspace(*eq)) + eq++; + params->wthread_max = u; + + if (*eq == '\0') + return; + + if (*eq != ',') + usage(); + u = strtoul(++eq, &ep, 0); + if (ep == eq) + usage(); + while (isspace(*ep)) + ep++; + if (*ep != '\0') + usage(); + params->wthread_timeout = u; } /*-------------------------------------------------------------------- From phk at projects.linpro.no Tue Jan 30 12:17:59 2007 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 30 Jan 2007 13:17:59 +0100 (CET) Subject: r1240 - trunk/varnish-cache/include Message-ID: <20070130121759.074951EC412@projects.linpro.no> Author: phk Date: 2007-01-30 13:17:58 +0100 (Tue, 30 Jan 2007) New Revision: 1240 Modified: trunk/varnish-cache/include/stat_field.h Log: Forgotten commit: Update backend stats fields Modified: trunk/varnish-cache/include/stat_field.h =================================================================== --- trunk/varnish-cache/include/stat_field.h 2007-01-29 22:06:33 UTC (rev 1239) +++ trunk/varnish-cache/include/stat_field.h 2007-01-30 12:17:58 UTC (rev 1240) @@ -36,7 +36,9 @@ MAC_STAT(cache_hitpass, uint64_t, "u", "Cache hits for pass") MAC_STAT(cache_miss, uint64_t, "u", "Cache misses") -MAC_STAT(backend_conn, uint64_t, "u", "Backend connections initiated") +MAC_STAT(backend_conn, uint64_t, "u", "Backend connections success") +MAC_STAT(backend_fail, uint64_t, "u", "Backend connections failures") +MAC_STAT(backend_reuse, uint64_t, "u", "Backend connections reuses") MAC_STAT(backend_recycle, uint64_t, "u", "Backend connections recycles") MAC_STAT(backend_unused, uint64_t, "u", "Backend connections unused")