comparison src/http/ngx_http_cache.c @ 99:a059e1aa65d4

nginx-0.0.1-2003-06-02-19:24:30 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 02 Jun 2003 15:24:30 +0000
parents 70d2345a903f
children 00bee6e7b485
comparison
equal deleted inserted replaced
98:c9b243802a17 99:a059e1aa65d4
1 1
2
3 /*
4 * small file in malloc()ed memory, mmap()ed file, file descriptor only,
5 * file access time only (to estimate can pages pages still be in memory),
6 * translated URI (ngx_http_index_hanlder),
7 * compiled script (ngx_http_ssi_filter).
8 */
2 9
3 10
4 #define NGX_HTTP_CACHE_ENTRY_DELETED 0x00000001 11 #define NGX_HTTP_CACHE_ENTRY_DELETED 0x00000001
5 #define NGX_HTTP_CACHE_ENTRY_MMAPED 0x00000002 12 #define NGX_HTTP_CACHE_ENTRY_MMAPED 0x00000002
6 13
7 /* "/" -> "/index.html" in ngx_http_index_handler */ 14 /* "/" -> "/index.html" in ngx_http_index_handler */
8 #define NGX_HTTP_CACHE_ENTRY_URI 0x00000004 15 #define NGX_HTTP_CACHE_ENTRY_URI 0x00000004
16
17 /* complied script */
18 #define NGX_HTTP_CACHE_ENTRY_SCRIPT 0x00000008
9 19
10 #define NGX_HTTP_CACHE_FILTER_FLAGS 0xFFFF0000 20 #define NGX_HTTP_CACHE_FILTER_FLAGS 0xFFFF0000
11 21
12 22
13 typedef struct { 23 typedef struct {
40 ngx_str_t *uri, ngx_http_cache_handle_t *h) 50 ngx_str_t *uri, ngx_http_cache_handle_t *h)
41 { 51 {
42 int hi; 52 int hi;
43 ngx_http_cache_hash_entry_t *entry; 53 ngx_http_cache_hash_entry_t *entry;
44 54
45 h->crc = ngx_crc32(uri->data, uri->len); 55 h->crc = ngx_crc(uri->data, uri->len);
46 56
47 hi = h->crc % cache_hash->size; 57 hi = h->crc % cache_hash->size;
48 entry = cache_hash[hi].elts; 58 entry = cache_hash[hi].elts;
49 59
50 for (i = 0; i < cache_hash[hi].nelts; i++) { 60 for (i = 0; i < cache_hash[hi].nelts; i++) {
59 } 69 }
60 } 70 }
61 71
62 return NGX_ERROR; 72 return NGX_ERROR;
63 } 73 }
74
75
76 /* 32-bit crc16 */
77
78 int ngx_crc(char *data, size_t len)
79 {
80 u_int32_t sum;
81
82 for (sum = 0; len; len--) {
83 /*
84 * gcc 2.95.2 x86 compiles that operator into the single rol opcode.
85 * msvc 6.0sp2 compiles it into four opcodes.
86 */
87 sum = sum >> 1 | sum << 31;
88
89 sum += *data++;
90 }
91
92 return sum;
93 }