nxt_sendbuf.c (4:76c63e9b6322) nxt_sendbuf.c (13:3a52b2c3d3f1)
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8
9
10static nxt_bool_t nxt_sendbuf_copy(nxt_buf_mem_t *bm, nxt_buf_t *b,
11 size_t *copied);
12
13
14nxt_uint_t
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8
9
10static nxt_bool_t nxt_sendbuf_copy(nxt_buf_mem_t *bm, nxt_buf_t *b,
11 size_t *copied);
12
13
14nxt_uint_t
15nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb,
16 struct iovec *iov, nxt_uint_t niov_max)
17{
18 u_char *last;
19 size_t size, total;
20 nxt_buf_t *b;
21 nxt_uint_t n;
22
23 total = sb->size;
24 last = NULL;
25 n = (nxt_uint_t) -1;
26
27 for (b = sb->buf; b != NULL && total < sb->limit; b = b->next) {
28
29 nxt_prefetch(b->next);
30
31 if (nxt_buf_is_file(b)) {
32 break;
33 }
34
35 if (nxt_buf_is_mem(b)) {
36
37 size = b->mem.free - b->mem.pos;
38
39 if (size != 0) {
40
41 if (total + size > sb->limit) {
42 size = sb->limit - total;
43
44 if (size == 0) {
45 break;
46 }
47 }
48
49 if (b->mem.pos != last) {
50
51 if (++n >= niov_max) {
52 goto done;
53 }
54
55 iov[n].iov_base = b->mem.pos;
56 iov[n].iov_len = size;
57
58 } else {
59 iov[n].iov_len += size;
60 }
61
62 nxt_debug(task, "sendbuf: %ui, %p, %uz",
63 n, iov[n].iov_base, iov[n].iov_len);
64
65 total += size;
66 last = b->mem.pos + size;
67 }
68
69 } else {
70 sb->sync = 1;
71 sb->last |= nxt_buf_is_last(b);
72 }
73 }
74
75 n++;
76
77done:
78
79 sb->buf = b;
80
81 return n;
82}
83
84
85nxt_uint_t
15nxt_sendbuf_mem_coalesce(nxt_task_t *task, nxt_sendbuf_coalesce_t *sb)
16{
17 u_char *last;
18 size_t size, total;
19 nxt_buf_t *b;
20 nxt_uint_t n;
21
22 total = sb->size;

--- 330 unchanged lines hidden ---
86nxt_sendbuf_mem_coalesce(nxt_task_t *task, nxt_sendbuf_coalesce_t *sb)
87{
88 u_char *last;
89 size_t size, total;
90 nxt_buf_t *b;
91 nxt_uint_t n;
92
93 total = sb->size;

--- 330 unchanged lines hidden ---