r5756 - trunk/varnish-cache/bin/varnishd

phk at varnish-cache.org phk at varnish-cache.org
Tue Jan 18 10:06:45 CET 2011


Author: phk
Date: 2011-01-18 10:06:43 +0100 (Tue, 18 Jan 2011)
New Revision: 5756

Modified:
   trunk/varnish-cache/bin/varnishd/cache_esi.h
   trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c
Log:
Change VEC codes to make it possible to collapse length decoding
in ESI_Deliver()



Modified: trunk/varnish-cache/bin/varnishd/cache_esi.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi.h	2011-01-18 08:00:53 UTC (rev 5755)
+++ trunk/varnish-cache/bin/varnishd/cache_esi.h	2011-01-18 09:06:43 UTC (rev 5756)
@@ -27,10 +27,10 @@
  *
  */
 
-#define	VEC_V1	'B'
-#define	VEC_V2	'W'
-#define	VEC_V8	'L'
-#define	VEC_S1	'b'
-#define	VEC_S2	'w'
-#define	VEC_S8	'l'
+#define	VEC_V1	(0x40 + 1)
+#define	VEC_V2	(0x40 + 2)
+#define	VEC_V8	(0x40 + 8)
+#define	VEC_S1	(0x60 + 1)
+#define	VEC_S2	(0x60 + 2)
+#define	VEC_S8	(0x60 + 8)
 #define	VEC_INCL	'I'

Modified: trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c	2011-01-18 08:00:53 UTC (rev 5755)
+++ trunk/varnish-cache/bin/varnishd/cache_esi_deliver.c	2011-01-18 09:06:43 UTC (rev 5756)
@@ -138,13 +138,42 @@
 		(void)WRW_Write(sp->wrk, "\r\n", -1);
 }
 
+static ssize_t
+ved_decode_len(uint8_t **pp)
+{
+	uint8_t *p;
+	ssize_t l;
+
+	p = *pp;
+	switch (*p & 15) {
+	case 1:
+		l = p[1];
+		p += 2;
+		break;
+	case 2:
+		l = vbe16dec(p + 1);
+		p += 3;
+		break;
+	case 8:
+		l = vbe64dec(p + 1);
+		p += 9;
+		break;
+	default:
+		printf("%d\n",(*p & 15));
+		INCOMPL();
+	}
+	*pp = p;
+	assert(l > 0);
+	return (l);
+}
+
 void
 ESI_Deliver(struct sess *sp)
 {
 	struct storage *st;
 	uint8_t *p, *e, *q, *r;
 	unsigned off;
-	size_t l;
+	ssize_t l;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	st = sp->obj->esidata;
@@ -156,30 +185,11 @@
 	off = 0;
 
 	while (p < e) {
-		//usleep(10000);
-		//WRW_Flush(sp->wrk);
 		switch (*p) {
 		case VEC_V1:
-			l = p[1];
-			p += 2;
-			q = (void*)strchr((const char*)p, '\0');
-			assert (q > p);
-			esi_sendchunk(sp, p, q - p, st->ptr + off, l);
-			off += l;
-			p = q + 1;
-			break;
 		case VEC_V2:
-			l = vbe16dec(p + 1);
-			p += 3;
-			q = (void*)strchr((const char*)p, '\0');
-			assert (q > p);
-			esi_sendchunk(sp, p, q - p, st->ptr + off, l);
-			off += l;
-			p = q + 1;
-			break;
 		case VEC_V8:
-			l = vbe64dec(p + 1);
-			p += 9;
+			l = ved_decode_len(&p);
 			q = (void*)strchr((const char*)p, '\0');
 			assert (q > p);
 			esi_sendchunk(sp, p, q - p, st->ptr + off, l);
@@ -187,21 +197,10 @@
 			p = q + 1;
 			break;
 		case VEC_S1:
-			l = p[1];
-			p += 2;
-			Debug("SKIP1(%d)\n", (int)l);
-			off += l;
-			break;
 		case VEC_S2:
-			l = vbe16dec(p + 1);
-			p += 3;
-			Debug("SKIP2(%d)\n", (int)l);
-			off += l;
-			break;
 		case VEC_S8:
-			l = vbe64dec(p + 1);
-			p += 9;
-			Debug("SKIP8(%d)\n", (int)l);
+			l = ved_decode_len(&p);
+			Debug("SKIP1(%d)\n", (int)l);
 			off += l;
 			break;
 		case VEC_INCL:




More information about the varnish-commit mailing list