r4367 - trunk/varnish-cache/bin/varnishtest
phk at projects.linpro.no
phk at projects.linpro.no
Wed Nov 25 10:49:15 CET 2009
Author: phk
Date: 2009-11-25 10:49:15 +0100 (Wed, 25 Nov 2009)
New Revision: 4367
Modified:
trunk/varnish-cache/bin/varnishtest/vtc.h
trunk/varnish-cache/bin/varnishtest/vtc_client.c
trunk/varnish-cache/bin/varnishtest/vtc_http.c
trunk/varnish-cache/bin/varnishtest/vtc_server.c
Log:
Add a "accept" (server only) and "loop" action to the HTTP specs.
Modified: trunk/varnish-cache/bin/varnishtest/vtc.h
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.h 2009-11-24 20:02:33 UTC (rev 4366)
+++ trunk/varnish-cache/bin/varnishtest/vtc.h 2009-11-25 09:49:15 UTC (rev 4367)
@@ -63,7 +63,7 @@
void init_sema(void);
-void http_process(struct vtclog *vl, const char *spec, int sock, int client);
+void http_process(struct vtclog *vl, const char *spec, int sock, int sfd);
void cmd_server_genvcl(struct vsb *vsb);
Modified: trunk/varnish-cache/bin/varnishtest/vtc_client.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_client.c 2009-11-24 20:02:33 UTC (rev 4366)
+++ trunk/varnish-cache/bin/varnishtest/vtc_client.c 2009-11-25 09:49:15 UTC (rev 4367)
@@ -96,7 +96,7 @@
}
assert(fd >= 0);
vtc_log(vl, 3, "Connected to %s fd is %d", c->connect, fd);
- http_process(vl, c->spec, fd, 1);
+ http_process(vl, c->spec, fd, -1);
vtc_log(vl, 3, "Closing fd %d", fd);
TCP_close(&fd);
}
Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-11-24 20:02:33 UTC (rev 4366)
+++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-11-25 09:49:15 UTC (rev 4367)
@@ -40,6 +40,9 @@
#include <stdlib.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
#include "libvarnish.h"
#include "vct.h"
#include "miniobj.h"
@@ -53,7 +56,7 @@
unsigned magic;
#define HTTP_MAGIC 0x2f02169c
int fd;
- int client;
+ int sfd;
int timeout;
struct vtclog *vl;
@@ -69,6 +72,21 @@
char *resp[MAX_HDR];
};
+#define ONLY_CLIENT(hp, av) \
+ do { \
+ if (hp->sfd >= 0) \
+ vtc_log(hp->vl, 0, \
+ "\"%s\" only possible in client", av[0]); \
+ } while (0)
+
+#define ONLY_SERVER(hp, av) \
+ do { \
+ if (hp->sfd < 0) \
+ vtc_log(hp->vl, 0, \
+ "\"%s\" only possible in server", av[0]); \
+ } while (0)
+
+
/* XXX: we may want to vary this */
static const char * const nl = "\r\n";
@@ -452,7 +470,7 @@
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
- AN(hp->client);
+ ONLY_CLIENT(hp, av);
assert(!strcmp(av[0], "rxresp"));
av++;
@@ -486,7 +504,7 @@
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
- AZ(hp->client);
+ ONLY_SERVER(hp, av);
assert(!strcmp(av[0], "txresp"));
av++;
@@ -563,7 +581,7 @@
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
- AZ(hp->client);
+ ONLY_SERVER(hp, av);
assert(!strcmp(av[0], "rxreq"));
av++;
@@ -584,7 +602,7 @@
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
- AZ(hp->client);
+ ONLY_SERVER(hp, av);
assert(!strcmp(av[0], "rxhdrs"));
av++;
@@ -603,7 +621,7 @@
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
- AZ(hp->client);
+ ONLY_SERVER(hp, av);
assert(!strcmp(av[0], "rxbody"));
av++;
@@ -630,7 +648,7 @@
(void)cmd;
(void)vl;
CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
- AN(hp->client);
+ ONLY_CLIENT(hp, av);
assert(!strcmp(av[0], "txreq"));
av++;
@@ -739,6 +757,48 @@
}
/**********************************************************************
+ * close and accept a new connection
+ */
+
+static void
+cmd_http_accept(CMD_ARGS)
+{
+ struct http *hp;
+
+ (void)cmd;
+ (void)vl;
+ CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
+ AZ(av[1]);
+ assert(hp->sfd >= 0);
+ TCP_close(&hp->fd);
+ hp->fd = accept(hp->sfd, NULL, NULL);
+}
+
+/**********************************************************************
+ * loop operator
+ */
+
+static void
+cmd_http_loop(CMD_ARGS)
+{
+ struct http *hp;
+ unsigned n, m;
+ char *s;
+
+ CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC);
+ AN(av[1]);
+ AN(av[2]);
+ AZ(av[3]);
+ n = strtod(av[1], NULL);
+ for (m = 1 ; m <= n; m++) {
+ vtc_log(vl, 4, "Loop #%u", m);
+ s = strdup(av[2]);
+ AN(s);
+ parse_string(s, cmd, hp, vl);
+ }
+}
+
+/**********************************************************************
* Execute HTTP specifications
*/
@@ -757,24 +817,27 @@
{ "chunked", cmd_http_chunked },
{ "delay", cmd_delay },
{ "sema", cmd_sema },
+ { "accept", cmd_http_accept },
+ { "loop", cmd_http_loop },
{ NULL, NULL }
};
void
-http_process(struct vtclog *vl, const char *spec, int sock, int client)
+http_process(struct vtclog *vl, const char *spec, int sock, int sfd)
{
struct http *hp;
char *s, *q;
+ (void)sfd;
ALLOC_OBJ(hp, HTTP_MAGIC);
AN(hp);
hp->fd = sock;
- hp->vl = vl;
- hp->client = client;
hp->timeout = 3000;
hp->nrxbuf = 640*1024;
hp->vsb = vsb_newauto();
hp->rxbuf = malloc(hp->nrxbuf); /* XXX */
+ hp->sfd = sfd;
+ hp->vl = vl;
AN(hp->rxbuf);
AN(hp->vsb);
Modified: trunk/varnish-cache/bin/varnishtest/vtc_server.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_server.c 2009-11-24 20:02:33 UTC (rev 4366)
+++ trunk/varnish-cache/bin/varnishtest/vtc_server.c 2009-11-25 09:49:15 UTC (rev 4367)
@@ -101,7 +101,7 @@
l = sizeof addr_s;
fd = accept(s->sock, addr, &l);
vtc_log(vl, 3, "Accepted socket fd is %d", fd);
- http_process(vl, s->spec, fd, 0);
+ http_process(vl, s->spec, fd, s->sock);
vtc_log(vl, 3, "shutting fd %d", fd);
assert((shutdown(fd, SHUT_WR) == 0)
|| errno == ENOTCONN || errno == ECONNRESET);
More information about the varnish-commit
mailing list