Revision: 14716
Author: adrian.chadd
Date: Sat Jun 19 05:59:24 2010
Log: Revert r14672 for now. This introduced some instabilities in the codebase.


http://code.google.com/p/lusca-cache/source/detail?r=14716

Modified:
 /branches/LUSCA_HEAD/libhttp/HttpHeader.c
 /branches/LUSCA_HEAD/libhttp/HttpHeader.h

=======================================
--- /branches/LUSCA_HEAD/libhttp/HttpHeader.c   Sun May 16 16:05:06 2010
+++ /branches/LUSCA_HEAD/libhttp/HttpHeader.c   Sat Jun 19 05:59:24 2010
@@ -162,7 +162,7 @@
     debug(55, 7) ("init-ing hdr: %p owner: %d\n", hdr, owner);
     memset(hdr, 0, sizeof(*hdr));
     hdr->owner = owner;
-    vector_init(&hdr->entries, sizeof(HttpHeaderEntry), 16);
+    arrayInit(&hdr->entries);
 }

 /*!
@@ -204,10 +204,10 @@
      * has been used.  As a hack, just never count zero-sized header
      * arrays.
      */
-    if (vector_numentries(&hdr->entries))
- statHistCount(&HttpHeaderStats[hdr->owner].hdrUCountDistr, vector_numentries(&hdr->entries));
+    if (0 != hdr->entries.count)
+ statHistCount(&HttpHeaderStats[hdr->owner].hdrUCountDistr, hdr->entries.count);
     HttpHeaderStats[hdr->owner].destroyedCount++;
- HttpHeaderStats[hdr->owner].busyDestroyedCount += vector_numentries(&hdr->entries) > 0; + HttpHeaderStats[hdr->owner].busyDestroyedCount += hdr->entries.count > 0;
     while ((e = httpHeaderGetEntry(hdr, &pos))) {
         /* tmp hack to try to avoid coredumps */
         if (e->id >= HDR_ENUM_END) {
@@ -217,9 +217,10 @@
statHistCount(&HttpHeaderStats[hdr->owner].fieldTypeDistr, e->id);
             /* yes, this destroy() leaves us in an inconsistent state */
             httpHeaderEntryDestroy(e);
+           memPoolFree(pool_http_header_entry, e);
         }
     }
-    vector_done(&hdr->entries);
+    arrayClean(&hdr->entries);
 }

 /* just handy in parsing: resets and returns false */
@@ -270,24 +271,15 @@
     hdr->len += strLen(e->name) + 2 + strLen(e->value) + 2;
 }

-HttpHeaderEntry *
-httpHeaderAllocNewEntry(HttpHeader *hdr)
-{
-       HttpHeaderEntry *e;
-
-       e = vector_append(&hdr->entries);
-       e->active = 0;
-       return e;
-}
-
-HttpHeaderEntry *
-httpHeaderAllocInsertEntry(HttpHeader *hdr, int pos)
-{
-       HttpHeaderEntry *e;
-
-       e = vector_insert(&hdr->entries, pos);
-       e->active = 0;
-       return e;
+/* appends an entry;
+ * does not call httpHeaderEntryClone() so one should not reuse "*e"
+ */
+void
+httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e)
+{
+ debug(55, 7) ("%p adding entry: %d at %d\n", hdr, e->id, hdr->entries.count);
+    httpHeaderAddInfo(hdr, e);
+    arrayAppend(&hdr->entries, e);
 }

 /*!
@@ -320,22 +312,21 @@
 /*
  * -1 means "don't know length, call strlen()
  */
-HttpHeaderEntry *
+int
httpHeaderAddEntryStr2(HttpHeader *hdr, http_hdr_type id, const char *a, int al, const char *v, int vl)
 {
-       HttpHeaderEntry *e = httpHeaderAllocNewEntry(hdr);
+       HttpHeaderEntry *e = memPoolAlloc(pool_http_header_entry);
        httpHeaderEntryCreate(e, id, a, al, v, vl);
-       httpHeaderAddInfo(hdr, e);
-       return e;
+       httpHeaderAddEntry(hdr, e);
+       return(hdr->entries.count - 1);
 }

-HttpHeaderEntry *
+void
httpHeaderAddEntryString(HttpHeader *hdr, http_hdr_type id, const String *a, const String *v)
 {
-       HttpHeaderEntry *e = httpHeaderAllocNewEntry(hdr);
+       HttpHeaderEntry *e = memPoolAlloc(pool_http_header_entry);
        httpHeaderEntryCreateStr(e, id, a, v);
-       httpHeaderAddInfo(hdr, e);
-       return e;
+       httpHeaderAddEntry(hdr, e);
 }

 /*!
@@ -363,23 +354,31 @@
 void
httpHeaderInsertEntryStr(HttpHeader *hdr, int pos, http_hdr_type id, const char *attrib, const char *value)
 {
-       HttpHeaderEntry *e = httpHeaderAllocInsertEntry(hdr, pos);
+       HttpHeaderEntry *e = memPoolAlloc(pool_http_header_entry);
        httpHeaderEntryCreate(e, id, attrib, -1, value, -1);
-       httpHeaderAddInfo(hdr, e);
+       httpHeaderInsertEntry(hdr, e, pos);
 }

+/* inserts an entry at the given position;
+ * does not call httpHeaderEntryClone() so one should not reuse "*e"
+ */
+void
+httpHeaderInsertEntry(HttpHeader * hdr, HttpHeaderEntry * e, int pos)
+{
+ debug(55, 7) ("%p adding entry: %d at %d\n", hdr, e->id, hdr->entries.count);
+    httpHeaderAddInfo(hdr, e);
+    arrayInsert(&hdr->entries, e, pos);
+}

 /* returns next valid entry */
 HttpHeaderEntry *
 httpHeaderGetEntry(const HttpHeader * hdr, HttpHeaderPos * pos)
 {
-    HttpHeaderEntry *e;
     assert(hdr && pos);
- assert(*pos >= HttpHeaderInitPos && *pos < vector_numentries(&hdr->entries));
-    for ((*pos)++; *pos < vector_numentries(&hdr->entries); (*pos)++) {
-       e = vector_get(&hdr->entries, *pos);
-       if (e->active)
-               return e;
+    assert(*pos >= HttpHeaderInitPos && *pos < hdr->entries.count);
+    for ((*pos)++; *pos < hdr->entries.count; (*pos)++) {
+        if (hdr->entries.items[*pos])
+            return hdr->entries.items[*pos];
     }
     return NULL;
 }
@@ -387,9 +386,9 @@
 void
 httpHeaderAddClone(HttpHeader * hdr, const HttpHeaderEntry * e)
 {
-    HttpHeaderEntry *ne = httpHeaderAllocNewEntry(hdr);
+    HttpHeaderEntry *ne = memPoolAlloc(pool_http_header_entry);
     httpHeaderEntryClone(ne, e);
-    httpHeaderAddInfo(hdr, ne);
+    httpHeaderAddEntry(hdr, ne);
 }

 /*!
@@ -475,11 +474,14 @@
 httpHeaderDelAt(HttpHeader * hdr, HttpHeaderPos pos)
 {
     HttpHeaderEntry *e;
- assert(pos >= HttpHeaderInitPos && pos < vector_numentries(&hdr->entries));
-    e = vector_get(&hdr->entries, pos);
+    assert(pos >= HttpHeaderInitPos && pos < hdr->entries.count);
+    e = hdr->entries.items[pos];
+    hdr->entries.items[pos] = NULL;
+    /* decrement header length, allow for ": " and crlf */
     hdr->len -= strLen(e->name) + 2 + strLen(e->value) + 2;
     assert(hdr->len >= 0);
     httpHeaderEntryDestroy(e);
+    memPoolFree(pool_http_header_entry, e);
 }

 int
@@ -619,24 +621,21 @@
 {
     HttpHeaderPos dp = HttpHeaderInitPos;
     HttpHeaderPos pos = HttpHeaderInitPos;
-    HttpHeaderEntry *e;

/* XXX breaks layering for now! ie, getting grubby fingers in without httpHeaderEntryGet() */
     dp = 0;
     pos = 0;
-    while (dp < vector_numentries(&hdr->entries)) {
- for (; dp < vector_numentries(&hdr->entries) && ((HttpHeaderEntry *) vector_get(&hdr->entries, dp))->active == 0; dp++);
-        if (dp >= vector_numentries(&hdr->entries))
+    while (dp < hdr->entries.count) {
+ for (; dp < hdr->entries.count && hdr->entries.items[dp] == NULL; dp++);
+        if (dp >= hdr->entries.count)
             break;
-        if (dp != pos) {
-               (void) vector_copy_item(&hdr->entries, pos, dp);
-               e = vector_get(&hdr->entries, dp);
-               e->active = 0;
-       }
+        hdr->entries.items[pos] = hdr->entries.items[dp];
+        if (dp != pos)
+            hdr->entries.items[dp] = NULL;
         pos++;
         dp++;
     }
-    vector_shrink(&hdr->entries, pos);
+    arrayShrink(&hdr->entries, pos);
 }

 /* use fresh entries to replace old ones */
=======================================
--- /branches/LUSCA_HEAD/libhttp/HttpHeader.h   Sun May 16 16:05:06 2010
+++ /branches/LUSCA_HEAD/libhttp/HttpHeader.h   Sat Jun 19 05:59:24 2010
@@ -13,7 +13,7 @@

 struct _HttpHeader {
     /* protected, do not use these, use interface functions instead */
-    Vector entries;            /* parsed entries in raw format */
+    Array entries;              /* parsed entries in raw format */
     HttpHeaderMask mask;        /* bit set <=> entry present */
     http_hdr_owner_type owner;  /* request or reply */
int len; /* length when packed, not counting terminating '\0' */
@@ -29,6 +29,7 @@
 typedef struct _TimeOrTag TimeOrTag;

 extern HttpHeaderFieldInfo *Headers;
+extern MemPool * pool_http_header_entry;

 /* XXX as mentioned in HttpHeader.c ; these probably shouldn't be here? */
 extern HttpHeaderMask ListHeadersMask;
@@ -47,14 +48,16 @@
 extern void httpHeaderClean(HttpHeader * hdr);
 extern int httpHeaderReset(HttpHeader * hdr);
extern void httpHeaderAddClone(HttpHeader * hdr, const HttpHeaderEntry * e);
+extern void httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e);
+extern void httpHeaderInsertEntry(HttpHeader * hdr, HttpHeaderEntry * e, int pos);
 extern void httpHeaderAppend(HttpHeader * dest, const HttpHeader * src);
extern HttpHeaderEntry *httpHeaderGetEntry(const HttpHeader * hdr, HttpHeaderPos * pos); extern HttpHeaderEntry *httpHeaderFindEntry(const HttpHeader * hdr, http_hdr_type id); extern HttpHeaderEntry *httpHeaderFindLastEntry(const HttpHeader * hdr, http_hdr_type id);

extern void httpHeaderAddEntryStr(HttpHeader *hdr, http_hdr_type id, const char *attrib, const char *value); -extern HttpHeaderEntry * httpHeaderAddEntryStr2(HttpHeader *hdr, http_hdr_type id, const char *attrib, int attrib_len, const char *value, int value_len); -extern HttpHeaderEntry * httpHeaderAddEntryString(HttpHeader *hdr, http_hdr_type id, const String *a, const String *v); +extern int httpHeaderAddEntryStr2(HttpHeader *hdr, http_hdr_type id, const char *attrib, int attrib_len, const char *value, int value_len); +extern void httpHeaderAddEntryString(HttpHeader *hdr, http_hdr_type id, const String *a, const String *v);

extern void httpHeaderInsertEntryStr(HttpHeader *hdr, int pos, http_hdr_type id, const char *attrib, const char *value);

@@ -72,9 +75,4 @@
 /* append/update */
extern void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask);

-/* new stuff */
-extern HttpHeaderEntry * httpHeaderAllocNewEntry(HttpHeader *hdr);
-extern HttpHeaderEntry * httpHeaderAllocInsertEntry(HttpHeader *hdr, int pos);
-
-
 #endif

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to