"Fossies" - the Fresh Open Source Software Archive

Member "haproxy-2.0.9/src/hdr_idx.c" (15 Nov 2019, 1814 Bytes) of package /linux/misc/haproxy-2.0.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "hdr_idx.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Header indexation functions.
    3  *
    4  * Copyright 2000-2011 Willy Tarreau <w@1wt.eu>
    5  *
    6  * This program is free software; you can redistribute it and/or
    7  * modify it under the terms of the GNU General Public License
    8  * as published by the Free Software Foundation; either version
    9  * 2 of the License, or (at your option) any later version.
   10  *
   11  */
   12 
   13 #include <common/config.h>
   14 #include <common/memory.h>
   15 #include <proto/hdr_idx.h>
   16 
   17 struct pool_head *pool_head_hdr_idx = NULL;
   18 
   19 /*
   20  * Add a header entry to <list> after element <after>. <after> is ignored when
   21  * the list is empty or full. Common usage is to set <after> to list->tail.
   22  *
   23  * Returns the position of the new entry in the list (from 1 to size-1), or 0
   24  * if the array is already full. An effort is made to fill the array linearly,
   25  * but once the last entry has been used, we have to search for unused blocks,
   26  * which takes much more time. For this reason, it's important to size is
   27  * appropriately.
   28  */
   29 int hdr_idx_add(int len, int cr, struct hdr_idx *list, int after)
   30 {
   31     register struct hdr_idx_elem e = { .len=0, .cr=0, .next=0};
   32     int new;
   33 
   34     e.len = len;
   35     e.cr = cr;
   36 
   37     if (list->used == list->size) {
   38         /* list is full */
   39         return -1;
   40     }
   41 
   42 
   43     if (list->last < list->size) {
   44         /* list is not completely used, we can fill linearly */
   45         new = list->last++;
   46     } else {
   47         /* That's the worst situation :
   48          * we have to scan the list for holes. We know that we
   49          * will find a place because the list is not full.
   50          */
   51         new = 1;
   52         while (list->v[new].len)
   53             new++;
   54     }
   55     
   56     /* insert the new element between <after> and the next one (or end) */
   57     e.next = list->v[after].next;
   58     list->v[after].next = new;
   59 
   60     list->used++;
   61     list->v[new] = e;
   62     list->tail = new;
   63     return new;
   64 }
   65 
   66 
   67 /*
   68  * Local variables:
   69  *  c-indent-level: 8
   70  *  c-basic-offset: 8
   71  * End:
   72  */