Commit 7d5a519f authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Simon Stridsberg

vtc_http2: Automatic stream identifier

parent 48c299c1
varnishtest "Automatic stream numbers"
server s1 {
loop 4 {
stream next {
rxreq
txresp
} -run
}
} -start
client c1 -connect ${s1_sock} {
loop 3 {
stream next {
txreq
rxresp
} -run
}
stream 7 {
txreq
rxresp
} -run
} -run
......@@ -86,6 +86,7 @@ struct http {
pthread_t tp;
VTAILQ_HEAD(, stream) streams;
unsigned last_stream;
pthread_mutex_t mtx;
pthread_cond_t cond;
struct hpk_ctx *encctx;
......
......@@ -2639,9 +2639,17 @@ stream_thread(void *priv)
static struct stream *
stream_new(const char *name, struct http *h)
{
char *p;
char *p, buf[20];
struct stream *s;
if (!strcmp("next", name)) {
if (h->last_stream > 0)
bprintf(buf, "%d", h->last_stream + 2);
else
bprintf(buf, "%d", 1);
name = buf;
}
ALLOC_OBJ(s, STREAM_MAGIC);
AN(s);
AZ(pthread_cond_init(&s->cond, NULL));
......@@ -2663,6 +2671,7 @@ stream_new(const char *name, struct http *h)
CHECK_OBJ_NOTNULL(h, HTTP_MAGIC);
s->hp = h;
h->last_stream = s->id;
//bprintf(s->connect, "%s", "${v1_sock}");
AZ(pthread_mutex_lock(&h->mtx));
......@@ -2768,7 +2777,8 @@ stream_run(struct stream *s)
* stream ID [SPEC] [ACTION]
*
* ID is the HTTP/2 stream number, while SPEC describes what will be
* done in that stream.
* done in that stream. If ID has the value ``next``, the actual stream
* number is computed based on the last one.
*
* Note that, when parsing a stream action, if the entity isn't operating
* in HTTP/2 mode, these spec is ran before::
......@@ -2837,7 +2847,7 @@ cmd_stream(CMD_ARGS)
continue;
}
if (**av == '-')
vtc_fatal(vl, "Unknown client argument: %s", *av);
vtc_fatal(vl, "Unknown stream argument: %s", *av);
REPLACE(s->spec, *av);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment