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