0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9
|
|
10
|
48
|
11 ngx_buf_t *
|
|
12 ngx_create_temp_buf(ngx_pool_t *pool, size_t size)
|
0
|
13 {
|
|
14 ngx_buf_t *b;
|
|
15
|
50
|
16 b = ngx_calloc_buf(pool);
|
|
17 if (b == NULL) {
|
0
|
18 return NULL;
|
|
19 }
|
|
20
|
50
|
21 b->start = ngx_palloc(pool, size);
|
|
22 if (b->start == NULL) {
|
0
|
23 return NULL;
|
|
24 }
|
|
25
|
48
|
26 /*
|
|
27 * set by ngx_calloc_buf():
|
|
28 *
|
|
29 * b->file_pos = 0;
|
|
30 * b->file_last = 0;
|
|
31 * b->file = NULL;
|
|
32 * b->shadow = NULL;
|
|
33 * b->tag = 0;
|
|
34 *
|
|
35 */
|
|
36
|
0
|
37 b->pos = b->start;
|
|
38 b->last = b->start;
|
|
39 b->end = b->last + size;
|
|
40 b->temporary = 1;
|
|
41
|
|
42 return b;
|
|
43 }
|
|
44
|
|
45
|
48
|
46 ngx_chain_t *
|
|
47 ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs)
|
0
|
48 {
|
|
49 u_char *p;
|
|
50 ngx_int_t i;
|
|
51 ngx_buf_t *b;
|
|
52 ngx_chain_t *chain, *cl, **ll;
|
|
53
|
50
|
54 p = ngx_palloc(pool, bufs->num * bufs->size);
|
|
55 if (p == NULL) {
|
0
|
56 return NULL;
|
|
57 }
|
|
58
|
|
59 ll = &chain;
|
|
60
|
|
61 for (i = 0; i < bufs->num; i++) {
|
50
|
62
|
|
63 b = ngx_calloc_buf(pool);
|
|
64 if (b == NULL) {
|
0
|
65 return NULL;
|
|
66 }
|
|
67
|
48
|
68 /*
|
|
69 * set by ngx_calloc_buf():
|
|
70 *
|
|
71 * b->file_pos = 0;
|
|
72 * b->file_last = 0;
|
|
73 * b->file = NULL;
|
|
74 * b->shadow = NULL;
|
|
75 * b->tag = 0;
|
|
76 *
|
|
77 */
|
|
78
|
0
|
79 b->pos = p;
|
|
80 b->last = p;
|
|
81 b->temporary = 1;
|
|
82
|
|
83 b->start = p;
|
|
84 p += bufs->size;
|
|
85 b->end = p;
|
|
86
|
50
|
87 cl = ngx_alloc_chain_link(pool);
|
|
88 if (cl == NULL) {
|
0
|
89 return NULL;
|
|
90 }
|
|
91
|
|
92 cl->buf = b;
|
|
93 *ll = cl;
|
|
94 ll = &cl->next;
|
|
95 }
|
|
96
|
|
97 *ll = NULL;
|
|
98
|
|
99 return chain;
|
|
100 }
|
|
101
|
|
102
|
48
|
103 ngx_int_t
|
|
104 ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in)
|
0
|
105 {
|
|
106 ngx_chain_t *cl, **ll;
|
|
107
|
|
108 ll = chain;
|
|
109
|
|
110 for (cl = *chain; cl; cl = cl->next) {
|
|
111 ll = &cl->next;
|
|
112 }
|
|
113
|
|
114 while (in) {
|
50
|
115 cl = ngx_alloc_chain_link(pool);
|
|
116 if (cl == NULL) {
|
|
117 return NGX_ERROR;
|
|
118 }
|
0
|
119
|
|
120 cl->buf = in->buf;
|
|
121 *ll = cl;
|
|
122 ll = &cl->next;
|
|
123 in = in->next;
|
|
124 }
|
|
125
|
|
126 *ll = NULL;
|
|
127
|
|
128 return NGX_OK;
|
|
129 }
|
|
130
|
|
131
|
48
|
132 void
|
|
133 ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy,
|
|
134 ngx_chain_t **out, ngx_buf_tag_t tag)
|
0
|
135 {
|
48
|
136 ngx_chain_t *cl;
|
0
|
137
|
|
138 if (*busy == NULL) {
|
|
139 *busy = *out;
|
|
140
|
|
141 } else {
|
48
|
142 for (cl = *busy; cl->next; cl = cl->next) { /* void */ }
|
4
|
143
|
48
|
144 cl->next = *out;
|
0
|
145 }
|
|
146
|
|
147 *out = NULL;
|
|
148
|
|
149 while (*busy) {
|
|
150 if (ngx_buf_size((*busy)->buf) != 0) {
|
|
151 break;
|
|
152 }
|
|
153
|
18
|
154 #if (NGX_HAVE_WRITE_ZEROCOPY)
|
0
|
155 if ((*busy)->buf->zerocopy_busy) {
|
|
156 break;
|
|
157 }
|
|
158 #endif
|
|
159
|
|
160 if ((*busy)->buf->tag != tag) {
|
|
161 *busy = (*busy)->next;
|
|
162 continue;
|
|
163 }
|
|
164
|
2
|
165 (*busy)->buf->pos = (*busy)->buf->start;
|
|
166 (*busy)->buf->last = (*busy)->buf->start;
|
0
|
167
|
48
|
168 cl = *busy;
|
|
169 *busy = cl->next;
|
|
170 cl->next = *free;
|
|
171 *free = cl;
|
0
|
172 }
|
|
173 }
|