r1681 - trunk/varnish-tools/fetcher

des at projects.linpro.no des at projects.linpro.no
Fri Jul 13 00:41:08 CEST 2007


Author: des
Date: 2007-07-13 00:41:08 +0200 (Fri, 13 Jul 2007)
New Revision: 1681

Modified:
   trunk/varnish-tools/fetcher/fetcher.pl
Log:
Allow a delay to be specified.  Note that the delay is applied individually
by each child.


Modified: trunk/varnish-tools/fetcher/fetcher.pl
===================================================================
--- trunk/varnish-tools/fetcher/fetcher.pl	2007-07-12 22:40:02 UTC (rev 1680)
+++ trunk/varnish-tools/fetcher/fetcher.pl	2007-07-12 22:41:08 UTC (rev 1681)
@@ -43,6 +43,9 @@
 our %CHILD;
 our $BUSY;
 
+our $jobs = 1;
+our $delay = 0;
+
 sub new($$) {
     my ($this, $mux, $fh) = @_;
     my $class = ref($this) || $this;
@@ -77,6 +80,8 @@
 		$s->write("add $_\n");
 	    }
 	}
+	select(undef, undef, undef, $delay)
+	    if $delay;
 	$0 = "[fetcher] ready";
 	$s->write("ready\n");
     }
@@ -133,8 +138,8 @@
     }
 }
 
-sub fetcher($@) {
-    my ($n, @urls) = @_;
+sub fetcher(@) {
+    my (@urls) = @_;
 
     my $mux = new IO::Multiplex;
 
@@ -145,7 +150,7 @@
 
     # start children
     $BUSY = 0;
-    for (my $i = 0; $i < $n; ++$i) {
+    for (my $i = 0; $i < $jobs; ++$i) {
 	my ($s1, $s2);
 	socketpair($s1, $s2, AF_UNIX, SOCK_STREAM, PF_UNSPEC);
 	$s1->autoflush(1);
@@ -183,17 +188,17 @@
 
 sub usage() {
 
-    print STDERR "usage: $0 [-j n] URL ...\n";
+    print STDERR "usage: $0 [-d n] [-j n] URL ...\n";
     exit(1);
 }
 
 MAIN:{
-    my $jobs = 1;
-    GetOptions("j|jobs=i" => \$jobs)
+    GetOptions("j|jobs=i" => \$jobs,
+	       "d|delay=i" => \$delay)
 	or usage();
     $jobs > 0
 	or usage();
     @ARGV
 	or usage();
-    fetcher($jobs, @ARGV);
+    fetcher(@ARGV);
 }




More information about the varnish-commit mailing list