Klaus Demo nginx / 0593b63
undo the previous wrong commit Igor Sysoev 15 years ago
6 changed file(s) with 141 addition(s) and 181 deletion(s). Raw diff Collapse all Expand all
4646 return;
4747 }
4848
49 tree->insert(*root, node, sentinel);
49 /*
50 * The rbtree is currently used by event timers only. Timer values
51 * 1) are spread in small range, usually several minutes,
52 * 2) and overflow each 49 days, if milliseconds are stored in 32 bits.
53 * The below comparison takes into account that overflow.
54 *
55 * If there will be a necessity to use the rbtree for values with
56 * other comparison rules, then a whole "for ( ;; )" loop should
57 * be made as tree->insert() function.
58 */
59
60 temp = *root;
61
62 for ( ;; ) {
63
64 /* node->key < temp->key */
65
66 if ((ngx_rbtree_key_int_t) node->key - (ngx_rbtree_key_int_t) temp->key
67 < 0)
68 {
69 if (temp->left == sentinel) {
70 temp->left = node;
71 break;
72 }
73
74 temp = temp->left;
75 continue;
76 }
77
78 if (temp->right == sentinel) {
79 temp->right = node;
80 break;
81 }
82
83 temp = temp->right;
84 continue;
85 }
86
87 node->parent = temp;
88 node->left = sentinel;
89 node->right = sentinel;
90
5091
5192 /* re-balance tree */
5293
94135 ngx_rbtree_left_rotate(root, sentinel, node->parent->parent);
95136 }
96137 }
138
97139 }
98140
99141 ngx_rbt_black(*root);
100 }
101
102
103 void
104 ngx_rbtree_insert_timer_value(ngx_rbtree_node_t *temp, ngx_rbtree_node_t *node,
105 ngx_rbtree_node_t *sentinel)
106 {
107 for ( ;; ) {
108
109 /*
110 * Timer values
111 * 1) are spread in small range, usually several minutes,
112 * 2) and overflow each 49 days, if milliseconds are stored in 32 bits.
113 * The comparison takes into account that overflow.
114 */
115
116 if ((ngx_rbtree_key_int_t) node->key - (ngx_rbtree_key_int_t) temp->key
117 < 0)
118 {
119 /* node->key < temp->key */
120
121 if (temp->left == sentinel) {
122 temp->left = node;
123 break;
124 }
125
126 temp = temp->left;
127 continue;
128 }
129
130 if (temp->right == sentinel) {
131 temp->right = node;
132 break;
133 }
134
135 temp = temp->right;
136 }
137
138 node->parent = temp;
139 node->left = sentinel;
140 node->right = sentinel;
141142 }
142143
143144
2828
2929 typedef struct ngx_rbtree_s ngx_rbtree_t;
3030
31 typedef void (*ngx_rbtree_insert_pt) (ngx_rbtree_node_t *root,
31 typedef ngx_rbtree_node_t *(*ngx_rbtree_insert_pt) (ngx_rbtree_node_t *root,
3232 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
3333
3434 struct ngx_rbtree_s {
3535 ngx_rbtree_node_t *root;
3636 ngx_rbtree_node_t *sentinel;
37 ngx_rbtree_insert_pt insert;
37 /* ngx_rbtree_insert_pt insert; */
3838 };
3939
4040
4242 ngx_rbtree_node_t *node);
4343 void ngx_rbtree_delete(ngx_thread_volatile ngx_rbtree_t *tree,
4444 ngx_rbtree_node_t *node);
45 void ngx_rbtree_insert_timer_value(ngx_rbtree_node_t *root,
46 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
4745
4846
4947 static ngx_inline ngx_rbtree_node_t *
33 */
44
55
6 typedef struct ngx_slab_map_s ngx_slab_map_t;
76
8 struct ngx_http_slab_map_s {
9 uintptr_t mask;
10 ngx_slab_elt_t *next;
11 };
12
13
14 typedef struct {
15 ngx_slab_elt_t *slabs;
16
17 ngx_slab_elt_t *map;
18 size_t map_size;
19
20 size_t size;
21
22 } ngx_slab_t;
23
24
25 void *
26 ngx_slab_init(ngx_slab_pool_t *pool, size_t size)
7 void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size)
278 {
28 slab->map_size = (slab->size + ngx_pagesize - 1)
29 / (ngx_pagesize / sizeof(ngx_slab_map_t));
30
31
32 return NULL;
9 return NULL;
3310 }
34
35
36 void *
37 ngx_slab_alloc(ngx_slab_t *pool, size_t size)
38 {
39 n = size - 1;
40
41
42 return NULL;
43 }
687687 {
688688 size_t len;
689689 u_char *d, *s;
690 static u_char basis64[] = {
691 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
692 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
693 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63,
694 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,
695 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
696 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77,
697 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
698 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77,
699
700 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
701 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
702 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
703 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
704 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
705 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
706 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
707 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77
708 };
690 static u_char basis64[] =
691 { 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
692 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
693 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63,
694 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,
695 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
696 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77,
697 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
698 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77,
699
700 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
701 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
702 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
703 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
704 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
705 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
706 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
707 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77 };
709708
710709 for (len = 0; len < src->len; len++) {
711710 if (src->data[len] == '=') {
887886 uintptr_t
888887 ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
889888 {
890 ngx_uint_t i, n;
891 uint32_t *escape;
892 static u_char hex[] = "0123456789abcdef";
893
894 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */
895
896 static uint32_t uri[] = {
897 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
898
899 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
900 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */
901
902 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
903 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
904
905 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
906 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
907
908 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
909 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
910 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
911 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
912 };
913
914 /* " ", "#", "%", "+", "?", %00-%1F, %7F-%FF */
915
916 static uint32_t args[] = {
917 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
918
919 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
920 0x80000829, /* 1000 0000 0000 0000 0000 1000 0010 1001 */
921
922 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
923 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
924
925 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
926 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
927
928 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
929 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
930 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
931 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
932 };
933
934 /* " ", """, "%", "'", %00-%1F, %7F-%FF */
935
936 static uint32_t html[] = {
937 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
938
939 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
940 0x800000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */
941
942 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
943 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
944
945 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
946 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
947
948 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
949 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
950 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
951 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
952 };
889 ngx_uint_t i, n;
890 uint32_t *escape;
891 static u_char hex[] = "0123456789abcdef";
892
893 /* " ", "#", "%", "?", %00-%1F, %7F-%FF */
894
895 static uint32_t uri[] =
896 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
897
898 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
899 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */
900
901 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
902 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
903
904 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
905 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
906
907 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
908 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
909 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
910 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
911
912 /* " ", "#", "%", "+", "?", %00-%1F, %7F-%FF */
913
914 static uint32_t args[] =
915 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
916
917 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
918 0x80000829, /* 1000 0000 0000 0000 0000 1000 0010 1001 */
919
920 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
921 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
922
923 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
924 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
925
926 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
927 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
928 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
929 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
930
931 /* " ", """, "%", "'", %00-%1F, %7F-%FF */
932
933 static uint32_t html[] =
934 { 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
935
936 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
937 0x800000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */
938
939 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
940 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
941
942 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
943 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
944
945 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
946 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
947 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
948 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
953949
954950
955951 switch (type) {
2222 {
2323 ngx_event_timer_rbtree.root = &ngx_event_timer_sentinel;
2424 ngx_event_timer_rbtree.sentinel = &ngx_event_timer_sentinel;
25 ngx_event_timer_rbtree.insert = ngx_rbtree_insert_timer_value;
2625
2726 #if (NGX_THREADS)
2827
88 #include <ngx_http.h>
99
1010
11 static uint32_t usual[] = {
12 0xffffdbfe, /* 1111 1111 1111 1111 1101 1011 1111 1110 */
13
14 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
15 0x7fff37d6, /* 0111 1111 1111 1111 0011 0111 1101 0110 */
16
17 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
18 0xefffffff, /* 1110 1111 1111 1111 1111 1111 1111 1111 */
19
20 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
21 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
22
23 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
24 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
25 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
26 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
27 };
11 static uint32_t usual[] =
12 { 0xffffdbfe, /* 1111 1111 1111 1111 1101 1011 1111 1110 */
13
14 /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
15 0x7fff37d6, /* 0111 1111 1111 1111 0011 0111 1101 0110 */
16
17 /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
18 0xefffffff, /* 1110 1111 1111 1111 1111 1111 1111 1111 */
19
20 /* ~}| {zyx wvut srqp onml kjih gfed cba` */
21 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
22
23 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
24 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
25 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
26 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */ };
2827
2928
3029 /* gcc, icc, msvc and others compile these switches as an jump table */