comparison src/os/win32/ngx_wsasend_chain.c @ 7887:ecf2a9002b37

Win32: use only preallocated memory in send/recv chain functions. The ngx_wsasend_chain() and ngx_wsarecv_chain() functions were modified to use only preallocated memory, and the number of preallocated wsabufs was increased to 64.
author Ruslan Ermilov <ru@nginx.com>
date Mon, 05 Jul 2021 13:26:49 +0300
parents 2cd019520210
children
comparison
equal deleted inserted replaced
7886:7f5e3595caff 7887:ecf2a9002b37
8 #include <ngx_config.h> 8 #include <ngx_config.h>
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <ngx_event.h> 10 #include <ngx_event.h>
11 11
12 12
13 #define NGX_WSABUFS 8 13 #define NGX_WSABUFS 64
14 14
15 15
16 ngx_chain_t * 16 ngx_chain_t *
17 ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) 17 ngx_wsasend_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
18 { 18 {
45 * WSASend() will return undocumented WSAEINVAL error. 45 * WSASend() will return undocumented WSAEINVAL error.
46 */ 46 */
47 47
48 vec.elts = wsabufs; 48 vec.elts = wsabufs;
49 vec.size = sizeof(WSABUF); 49 vec.size = sizeof(WSABUF);
50 vec.nalloc = NGX_WSABUFS; 50 vec.nalloc = ngx_min(NGX_WSABUFS, ngx_max_wsabufs);
51 vec.pool = c->pool; 51 vec.pool = c->pool;
52 52
53 for ( ;; ) { 53 for ( ;; ) {
54 prev = NULL; 54 prev = NULL;
55 wsabuf = NULL; 55 wsabuf = NULL;
57 57
58 vec.nelts = 0; 58 vec.nelts = 0;
59 59
60 /* create the WSABUF and coalesce the neighbouring bufs */ 60 /* create the WSABUF and coalesce the neighbouring bufs */
61 61
62 for (cl = in; 62 for (cl = in; cl && send < limit; cl = cl->next) {
63 cl && vec.nelts < ngx_max_wsabufs && send < limit; 63
64 cl = cl->next)
65 {
66 if (ngx_buf_special(cl->buf)) { 64 if (ngx_buf_special(cl->buf)) {
67 continue; 65 continue;
68 } 66 }
69 67
70 size = cl->buf->last - cl->buf->pos; 68 size = cl->buf->last - cl->buf->pos;
75 73
76 if (prev == cl->buf->pos) { 74 if (prev == cl->buf->pos) {
77 wsabuf->len += cl->buf->last - cl->buf->pos; 75 wsabuf->len += cl->buf->last - cl->buf->pos;
78 76
79 } else { 77 } else {
78 if (vec.nelts == vec.nalloc) {
79 break;
80 }
81
80 wsabuf = ngx_array_push(&vec); 82 wsabuf = ngx_array_push(&vec);
81 if (wsabuf == NULL) { 83 if (wsabuf == NULL) {
82 return NGX_CHAIN_ERROR; 84 return NGX_CHAIN_ERROR;
83 } 85 }
84 86
167 */ 169 */
168 170
169 vec.elts = wsabufs; 171 vec.elts = wsabufs;
170 vec.nelts = 0; 172 vec.nelts = 0;
171 vec.size = sizeof(WSABUF); 173 vec.size = sizeof(WSABUF);
172 vec.nalloc = NGX_WSABUFS; 174 vec.nalloc = ngx_min(NGX_WSABUFS, ngx_max_wsabufs);
173 vec.pool = c->pool; 175 vec.pool = c->pool;
174 176
175 send = 0; 177 send = 0;
176 prev = NULL; 178 prev = NULL;
177 wsabuf = NULL; 179 wsabuf = NULL;
178 180
179 /* create the WSABUF and coalesce the neighbouring bufs */ 181 /* create the WSABUF and coalesce the neighbouring bufs */
180 182
181 for (cl = in; 183 for (cl = in; cl && send < limit; cl = cl->next) {
182 cl && vec.nelts < ngx_max_wsabufs && send < limit; 184
183 cl = cl->next)
184 {
185 if (ngx_buf_special(cl->buf)) { 185 if (ngx_buf_special(cl->buf)) {
186 continue; 186 continue;
187 } 187 }
188 188
189 size = cl->buf->last - cl->buf->pos; 189 size = cl->buf->last - cl->buf->pos;
194 194
195 if (prev == cl->buf->pos) { 195 if (prev == cl->buf->pos) {
196 wsabuf->len += cl->buf->last - cl->buf->pos; 196 wsabuf->len += cl->buf->last - cl->buf->pos;
197 197
198 } else { 198 } else {
199 if (vec.nelts == vec.nalloc) {
200 break;
201 }
202
199 wsabuf = ngx_array_push(&vec); 203 wsabuf = ngx_array_push(&vec);
200 if (wsabuf == NULL) { 204 if (wsabuf == NULL) {
201 return NGX_CHAIN_ERROR; 205 return NGX_CHAIN_ERROR;
202 } 206 }
203 207