annotate src/core/ngx_buf.c @ 7660:d33e17499088

Version bump.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 26 May 2020 22:03:00 +0300
parents da9941c9b01b
children c7a8bdf5af55
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 436
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 436
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
4412
d620f497c50f Copyright updated.
Maxim Konovalov <maxim@nginx.com>
parents: 4114
diff changeset
4 * Copyright (C) Nginx, Inc.
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 436
diff changeset
5 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 436
diff changeset
6
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7
42
cd035a94e0b6 nginx-0.0.1-2002-12-27-10:27:47 import
Igor Sysoev <igor@sysoev.ru>
parents: 16
diff changeset
8 #include <ngx_config.h>
100
7ebc8b7fb816 nginx-0.0.1-2003-06-03-19:42:58 import
Igor Sysoev <igor@sysoev.ru>
parents: 93
diff changeset
9 #include <ngx_core.h>
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
12 ngx_buf_t *
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
13 ngx_create_temp_buf(ngx_pool_t *pool, size_t size)
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
14 {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
15 ngx_buf_t *b;
16
6ce4755737b4 nginx-0.0.1-2002-09-26-20:50:29 import
Igor Sysoev <igor@sysoev.ru>
parents: 8
diff changeset
16
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
17 b = ngx_calloc_buf(pool);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
18 if (b == NULL) {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
19 return NULL;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
20 }
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
21
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
22 b->start = ngx_palloc(pool, size);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
23 if (b->start == NULL) {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
24 return NULL;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
25 }
166
389d7ee9fa60 nginx-0.0.1-2003-10-30-11:51:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 160
diff changeset
26
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
27 /*
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
28 * set by ngx_calloc_buf():
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
29 *
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
30 * b->file_pos = 0;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
31 * b->file_last = 0;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
32 * b->file = NULL;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
33 * b->shadow = NULL;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
34 * b->tag = 0;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
35 * and flags
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
36 */
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
37
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
38 b->pos = b->start;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
39 b->last = b->start;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
40 b->end = b->last + size;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
41 b->temporary = 1;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
43 return b;
0
4eff17414a43 nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
44 }
93
738fe44c70d5 nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 76
diff changeset
45
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
46
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
47 ngx_chain_t *
507
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
48 ngx_alloc_chain_link(ngx_pool_t *pool)
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
49 {
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
50 ngx_chain_t *cl;
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
51
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
52 cl = pool->chain;
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
53
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
54 if (cl) {
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
55 pool->chain = cl->next;
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
56 return cl;
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
57 }
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
58
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
59 cl = ngx_palloc(pool, sizeof(ngx_chain_t));
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
60 if (cl == NULL) {
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
61 return NULL;
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
62 }
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
63
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
64 return cl;
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
65 }
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
66
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
67
cd3117ad9aab nginx-0.1.28-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
68 ngx_chain_t *
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
69 ngx_create_chain_of_bufs(ngx_pool_t *pool, ngx_bufs_t *bufs)
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
70 {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
71 u_char *p;
290
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 239
diff changeset
72 ngx_int_t i;
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
73 ngx_buf_t *b;
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
74 ngx_chain_t *chain, *cl, **ll;
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
75
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
76 p = ngx_palloc(pool, bufs->num * bufs->size);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
77 if (p == NULL) {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
78 return NULL;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
79 }
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
80
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
81 ll = &chain;
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
82
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
83 for (i = 0; i < bufs->num; i++) {
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
84
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
85 b = ngx_calloc_buf(pool);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
86 if (b == NULL) {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
87 return NULL;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
88 }
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
89
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
90 /*
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
91 * set by ngx_calloc_buf():
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
92 *
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
93 * b->file_pos = 0;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
94 * b->file_last = 0;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
95 * b->file = NULL;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
96 * b->shadow = NULL;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
97 * b->tag = 0;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 507
diff changeset
98 * and flags
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
99 *
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
100 */
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
101
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
102 b->pos = p;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
103 b->last = p;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
104 b->temporary = 1;
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
105
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
106 b->start = p;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
107 p += bufs->size;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
108 b->end = p;
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
109
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
110 cl = ngx_alloc_chain_link(pool);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
111 if (cl == NULL) {
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
112 return NULL;
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
113 }
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
114
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
115 cl->buf = b;
160
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
116 *ll = cl;
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
117 ll = &cl->next;
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
118 }
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
119
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
120 *ll = NULL;
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
121
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
122 return chain;
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
123 }
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
124
e7e094d34162 nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
125
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
126 ngx_int_t
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
127 ngx_chain_add_copy(ngx_pool_t *pool, ngx_chain_t **chain, ngx_chain_t *in)
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
128 {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
129 ngx_chain_t *cl, **ll;
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
130
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
131 ll = chain;
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
132
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
133 for (cl = *chain; cl; cl = cl->next) {
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
134 ll = &cl->next;
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
135 }
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
136
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
137 while (in) {
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
138 cl = ngx_alloc_chain_link(pool);
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
139 if (cl == NULL) {
7282
da9941c9b01b Leave chain in ngx_chain_add_copy() in consistent state on errors.
Sergey Kandaurov <pluknet@nginx.com>
parents: 6874
diff changeset
140 *ll = NULL;
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
141 return NGX_ERROR;
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
142 }
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
143
343
6bdf858bff8c nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents: 290
diff changeset
144 cl->buf = in->buf;
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
145 *ll = cl;
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
146 ll = &cl->next;
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
147 in = in->next;
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
148 }
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
149
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
150 *ll = NULL;
136
da00cde00e8a nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents: 135
diff changeset
151
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
152 return NGX_OK;
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
153 }
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
154
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
155
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
156 ngx_chain_t *
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
157 ngx_chain_get_free_buf(ngx_pool_t *p, ngx_chain_t **free)
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
158 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
159 ngx_chain_t *cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
160
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
161 if (*free) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
162 cl = *free;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
163 *free = cl->next;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
164 cl->next = NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
165 return cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
166 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
167
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
168 cl = ngx_alloc_chain_link(p);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
169 if (cl == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
170 return NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
171 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
172
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
173 cl->buf = ngx_calloc_buf(p);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
174 if (cl->buf == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
175 return NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
176 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
177
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
178 cl->next = NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
179
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
180 return cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
181 }
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
182
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
183
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
184 void
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
185 ngx_chain_update_chains(ngx_pool_t *p, ngx_chain_t **free, ngx_chain_t **busy,
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
186 ngx_chain_t **out, ngx_buf_tag_t tag)
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
187 {
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
188 ngx_chain_t *cl;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
189
6797
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
190 if (*out) {
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
191 if (*busy == NULL) {
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
192 *busy = *out;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
193
6797
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
194 } else {
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
195 for (cl = *busy; cl->next; cl = cl->next) { /* void */ }
455
295d97d70c69 nginx-0.1.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 452
diff changeset
196
6797
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
197 cl->next = *out;
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
198 }
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
199
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
200 *out = NULL;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
201 }
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
202
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
203 while (*busy) {
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
204 cl = *busy;
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
205
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
206 if (ngx_buf_size(cl->buf) != 0) {
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
207 break;
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
208 }
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
209
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
210 if (cl->buf->tag != tag) {
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
211 *busy = cl->next;
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
212 ngx_free_chain(p, cl);
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
213 continue;
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
214 }
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
215
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
216 cl->buf->pos = cl->buf->start;
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
217 cl->buf->last = cl->buf->start;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
218
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
219 *busy = cl->next;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
220 cl->next = *free;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
221 *free = cl;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
222 }
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
223 }
5850
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
224
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
225
5915
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
226 off_t
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
227 ngx_chain_coalesce_file(ngx_chain_t **in, off_t limit)
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
228 {
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
229 off_t total, size, aligned, fprev;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
230 ngx_fd_t fd;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
231 ngx_chain_t *cl;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
232
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
233 total = 0;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
234
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
235 cl = *in;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
236 fd = cl->buf->file->fd;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
237
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
238 do {
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
239 size = cl->buf->file_last - cl->buf->file_pos;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
240
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
241 if (size > limit - total) {
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
242 size = limit - total;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
243
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
244 aligned = (cl->buf->file_pos + size + ngx_pagesize - 1)
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
245 & ~((off_t) ngx_pagesize - 1);
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
246
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
247 if (aligned <= cl->buf->file_last) {
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
248 size = aligned - cl->buf->file_pos;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
249 }
6874
7cc2d3a96ea3 Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6797
diff changeset
250
7cc2d3a96ea3 Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6797
diff changeset
251 total += size;
7cc2d3a96ea3 Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6797
diff changeset
252 break;
5915
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
253 }
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
254
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
255 total += size;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
256 fprev = cl->buf->file_pos + size;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
257 cl = cl->next;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
258
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
259 } while (cl
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
260 && cl->buf->in_file
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
261 && total < limit
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
262 && fd == cl->buf->file->fd
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
263 && fprev == cl->buf->file_pos);
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
264
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
265 *in = cl;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
266
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
267 return total;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
268 }
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
269
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
270
5850
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
271 ngx_chain_t *
5912
de68ed551bfb Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents: 5850
diff changeset
272 ngx_chain_update_sent(ngx_chain_t *in, off_t sent)
5850
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
273 {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
274 off_t size;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
275
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
276 for ( /* void */ ; in; in = in->next) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
277
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
278 if (ngx_buf_special(in->buf)) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
279 continue;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
280 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
281
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
282 if (sent == 0) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
283 break;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
284 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
285
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
286 size = ngx_buf_size(in->buf);
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
287
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
288 if (sent >= size) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
289 sent -= size;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
290
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
291 if (ngx_buf_in_memory(in->buf)) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
292 in->buf->pos = in->buf->last;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
293 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
294
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
295 if (in->buf->in_file) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
296 in->buf->file_pos = in->buf->file_last;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
297 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
298
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
299 continue;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
300 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
301
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
302 if (ngx_buf_in_memory(in->buf)) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
303 in->buf->pos += (size_t) sent;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
304 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
305
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
306 if (in->buf->in_file) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
307 in->buf->file_pos += sent;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
308 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
309
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
310 break;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
311 }
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
312
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
313 return in;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
314 }