r292 - in trunk/varnish-tools: . fetcher recursor

des at projects.linpro.no des at projects.linpro.no
Tue Jul 4 14:01:44 CEST 2006


Author: des
Date: 2006-07-04 14:01:44 +0200 (Tue, 04 Jul 2006)
New Revision: 292

Added:
   trunk/varnish-tools/fetcher/
   trunk/varnish-tools/fetcher/Makefile
   trunk/varnish-tools/fetcher/fetcher.c
   trunk/varnish-tools/recursor/
   trunk/varnish-tools/recursor/recursor.pl
Log:
Stuff we use for testing.

Added: trunk/varnish-tools/fetcher/Makefile
===================================================================
--- trunk/varnish-tools/fetcher/Makefile	2006-07-04 09:28:21 UTC (rev 291)
+++ trunk/varnish-tools/fetcher/Makefile	2006-07-04 12:01:44 UTC (rev 292)
@@ -0,0 +1,9 @@
+#
+# $Id$
+#
+
+PROG	 = fetcher
+WARNS	?= 6
+MAN	 =
+
+.include <bsd.prog.mk>


Property changes on: trunk/varnish-tools/fetcher/Makefile
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/varnish-tools/fetcher/fetcher.c
===================================================================
--- trunk/varnish-tools/fetcher/fetcher.c	2006-07-04 09:28:21 UTC (rev 291)
+++ trunk/varnish-tools/fetcher/fetcher.c	2006-07-04 12:01:44 UTC (rev 292)
@@ -0,0 +1,99 @@
+/*
+ * $Id$
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+
+#include <err.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <fetch.h>
+#include <stdlib.h>
+#include <string.h>
+
+static const char *req_pattern =
+"GET http://varnish-test-1.linpro.no/cgi-bin/recursor.pl?foo=%d HTTP/1.1\r\n"
+"Host: varnish-test-1.linpro.no\r\n"
+"Connection: keep\r\n"
+"\r\n";
+
+static const char *
+read_line(FILE *f)
+{
+	static char *buf;
+	static size_t bufsz;
+	const char *line;
+	size_t len;
+
+	if ((line = fgetln(f, &len)) == NULL)
+		return (NULL);
+	while (len && (line[len - 1] == '\r' || line[len - 1] == '\n'))
+		--len;
+	if (bufsz < len + 1) {
+		bufsz = len * 2;
+		if ((buf = realloc(buf, bufsz)) == NULL)
+			err(1, "realloc()");
+	}
+	memcpy(buf, line, len);
+	buf[len] = '\0';
+#ifdef DEBUG
+	fprintf(stderr, "<<< [%s]\n", buf);
+#endif
+	return (buf);
+}
+
+int
+main(void)
+{
+	struct addrinfo hints, *res;
+	int clen, code, ctr, error, sd;
+	const char *line;
+	FILE *f;
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = AF_INET;
+	hints.ai_socktype = SOCK_STREAM;
+	if ((error = getaddrinfo("varnish-test-2.linpro.no", "http", &hints, &res)) != 0)
+		errx(1, "%s", gai_strerror(error));
+	if ((sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0)
+		err(1, "socket()");
+	if (connect(sd, res->ai_addr, res->ai_addrlen) < 0)
+		err(1, "connect()");
+	if ((f = fdopen(sd, "w+")) == NULL)
+		err(1, "fdopen()");
+	for (ctr = 0; ctr < 5000; ++ctr) {
+		fprintf(stderr, "\r%d ", ctr);
+#ifdef DEBUG
+		fprintf(stderr, req_pattern, ctr);
+#endif
+		fprintf(f, req_pattern, ctr);
+
+		/* get response header */
+		if ((line = read_line(f)) == NULL)
+			errx(1, "protocol error");
+		if (sscanf(line, "HTTP/%*d.%*d %d %*s", &code) != 1)
+			errx(1, "protocol error");
+		if (code != 200)
+			errx(1, "code %d", code);
+
+		/* get content-length */
+		clen = -1;
+		for (;;) {
+			if ((line = read_line(f)) == NULL)
+				errx(1, "protocol error");
+			if (line[0] == '\0')
+				break;
+			sscanf(line, "Content-Length: %d\n", &clen);
+		}
+		if (clen == -1)
+			errx(1, "no content length");
+
+		/* eat contents */
+		while (clen--)
+			if (getc(f) == EOF)
+				errx(1, "connection prematurely closed");
+	}
+	fclose(f);
+	exit(0);
+}


Property changes on: trunk/varnish-tools/fetcher/fetcher.c
___________________________________________________________________
Name: svn:keywords
   + Id

Added: trunk/varnish-tools/recursor/recursor.pl
===================================================================
--- trunk/varnish-tools/recursor/recursor.pl	2006-07-04 09:28:21 UTC (rev 291)
+++ trunk/varnish-tools/recursor/recursor.pl	2006-07-04 12:01:44 UTC (rev 292)
@@ -0,0 +1,19 @@
+#!/usr/local/bin/perl -w
+#
+# $Id$
+#
+
+use strict;
+use CGI;
+
+my $q = new CGI;
+
+my $foo = int($q->param('foo'));
+my $i = ($foo * 2) % 5000;
+my $j = ($foo * 2 + 1) % 5000;
+
+print $q->header(-expires=>'+60m');
+
+print "<h1>Page $foo</h1>\n";
+print "<p><a href=\"/cgi-bin/recursor.pl?foo=$i\">Link $i</a></p>\n";
+print "<p><a href=\"/cgi-bin/recursor.pl?foo=$j\">Link $j</a></p>\n";


Property changes on: trunk/varnish-tools/recursor/recursor.pl
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:keywords
   + Id




More information about the varnish-commit mailing list