annotate src/core/ngx_buf.c @ 6874:7cc2d3a96ea3

Fixed trailer construction with limit on FreeBSD and macOS. The ngx_chain_coalesce_file() function may produce more bytes to send then requested in the limit passed, as it aligns the last file position to send to memory page boundary. As a result, (limit - send) may become negative. This resulted in big positive number when converted to size_t while calling ngx_output_chain_to_iovec(). Another part of the problem is in ngx_chain_coalesce_file(): it changes cl to the next chain link even if the current buffer is only partially sent due to limit. Therefore, if a file buffer was not expected to be fully sent due to limit, and was followed by a memory buffer, nginx called sendfile() with a part of the file buffer, and the memory buffer in trailer. If there were enough room in the socket buffer, this resulted in a part of the file buffer being skipped, and corresponding part of the memory buffer sent instead. The bug was introduced in 8e903522c17a (1.7.8). Configurations affected are ones using limits, that is, limit_rate and/or sendfile_max_chunk, and memory buffers after file ones (may happen when using subrequests or with proxying with disk buffering). Fix is to explicitly check if (send < limit) before constructing trailer with ngx_output_chain_to_iovec(). Additionally, ngx_chain_coalesce_file() was modified to preserve unfinished file buffers in cl.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 20 Jan 2017 21:12:48 +0300
parents 40c2f3e06d23
children da9941c9b01b
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) {
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
140 return NGX_ERROR;
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 499
diff changeset
141 }
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
142
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
143 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
144 *ll = cl;
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
145 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
146 in = in->next;
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
147 }
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
148
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
149 *ll = NULL;
136
da00cde00e8a nginx-0.0.1-2003-10-02-09:39:37 import
Igor Sysoev <igor@sysoev.ru>
parents: 135
diff changeset
150
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
151 return NGX_OK;
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 132
diff changeset
152 }
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
581
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
155 ngx_chain_t *
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
156 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
157 {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
158 ngx_chain_t *cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
159
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
160 if (*free) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
161 cl = *free;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
162 *free = cl->next;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
163 cl->next = NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
164 return cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
165 }
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 cl = ngx_alloc_chain_link(p);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
168 if (cl == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
169 return NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
170 }
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 cl->buf = ngx_calloc_buf(p);
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
173 if (cl->buf == NULL) {
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
174 return NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
175 }
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 cl->next = NULL;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
178
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
179 return cl;
326634fb9d47 nginx-0.3.12-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
180 }
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
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
183 void
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
184 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
185 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
186 {
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
187 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
188
6797
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
189 if (*out) {
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
190 if (*busy == NULL) {
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
191 *busy = *out;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
192
6797
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
193 } else {
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
194 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
195
6797
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
196 cl->next = *out;
40c2f3e06d23 Core: slight optimization in ngx_chain_update_chains().
hucongcong <hucong.c@foxmail.com>
parents: 5915
diff changeset
197 }
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 *out = NULL;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
200 }
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 while (*busy) {
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
203 cl = *busy;
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
204
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
205 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
206 break;
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
207 }
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
208
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
209 if (cl->buf->tag != tag) {
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
210 *busy = cl->next;
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
211 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
212 continue;
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
213 }
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
214
4114
5db098f97e0e API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents: 2414
diff changeset
215 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
216 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
217
499
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
218 *busy = cl->next;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
219 cl->next = *free;
64d9afb209da nginx-0.1.24-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
220 *free = cl;
132
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
221 }
949f45d1589a nginx-0.0.1-2003-09-24-20:44:13 import
Igor Sysoev <igor@sysoev.ru>
parents: 100
diff changeset
222 }
5850
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
223
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
224
5915
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
225 off_t
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
226 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
227 {
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
228 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
229 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
230 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
231
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
232 total = 0;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
233
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
234 cl = *in;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
235 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
236
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
237 do {
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
238 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
239
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
240 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
241 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
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
243 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
244 & ~((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
245
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
246 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
247 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
248 }
6874
7cc2d3a96ea3 Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6797
diff changeset
249
7cc2d3a96ea3 Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6797
diff changeset
250 total += size;
7cc2d3a96ea3 Fixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6797
diff changeset
251 break;
5915
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
252 }
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 total += size;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
255 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
256 cl = cl->next;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
257
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
258 } while (cl
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
259 && 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
260 && total < limit
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
261 && 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
262 && 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
263
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
264 *in = cl;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
265
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
266 return total;
ac3f78219f85 Moved the code for coalescing file buffers to a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 5912
diff changeset
267 }
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
5850
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
270 ngx_chain_t *
5912
de68ed551bfb Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().
Valentin Bartenev <vbart@nginx.com>
parents: 5850
diff changeset
271 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
272 {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
273 off_t size;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
274
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
275 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
276
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
277 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
278 continue;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
279 }
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 if (sent == 0) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
282 break;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
283 }
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 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
286
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
287 if (sent >= size) {
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
288 sent -= size;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
289
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
290 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
291 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
292 }
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 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
295 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
296 }
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 continue;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
299 }
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 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
302 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
303 }
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 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
306 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
307 }
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 break;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
310 }
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 return in;
f9c83484d9ce Moved the code for adjusting sent buffers in a separate function.
Valentin Bartenev <vbart@nginx.com>
parents: 4412
diff changeset
313 }