comparison src/os/unix/ngx_writev_chain.c @ 170:c42be4185301

nginx-0.0.1-2003-11-03-01:56:18 import
author Igor Sysoev <igor@sysoev.ru>
date Sun, 02 Nov 2003 22:56:18 +0000
parents ef8c87afcfc5
children 1bf718ce0dde
comparison
equal deleted inserted replaced
169:edf29bb717da 170:c42be4185301
9 char *prev; 9 char *prev;
10 ssize_t n, size; 10 ssize_t n, size;
11 off_t sent; 11 off_t sent;
12 struct iovec *iov; 12 struct iovec *iov;
13 ngx_err_t err; 13 ngx_err_t err;
14 ngx_array_t iovecs; 14 ngx_array_t io;
15 ngx_chain_t *ce; 15 ngx_chain_t *cl;
16 16
17 if (!c->write->ready) { 17 if (!c->write->ready) {
18 return in; 18 return in;
19 } 19 }
20 20
21 ngx_init_array(iovecs, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR); 21 ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR);
22 22
23 prev = NULL; 23 prev = NULL;
24 iov = NULL; 24 iov = NULL;
25 25
26 /* create the iovec and coalesce the neighbouring chain entries */ 26 /* create the iovec and coalesce the neighbouring hunks */
27 for (ce = in; ce; ce = ce->next) { 27 for (cl = in; cl; cl = cl->next) {
28 28
29 if (prev == ce->hunk->pos) { 29 if (prev == cl->hunk->pos) {
30 iov->iov_len += ce->hunk->last - ce->hunk->pos; 30 iov->iov_len += cl->hunk->last - cl->hunk->pos;
31 prev = ce->hunk->last; 31 prev = cl->hunk->last;
32 32
33 } else { 33 } else {
34 ngx_test_null(iov, ngx_push_array(&iovecs), NGX_CHAIN_ERROR); 34 ngx_test_null(iov, ngx_push_array(&io), NGX_CHAIN_ERROR);
35 iov->iov_base = ce->hunk->pos; 35 iov->iov_base = cl->hunk->pos;
36 iov->iov_len = ce->hunk->last - ce->hunk->pos; 36 iov->iov_len = cl->hunk->last - cl->hunk->pos;
37 prev = ce->hunk->last; 37 prev = cl->hunk->last;
38 } 38 }
39 } 39 }
40 40
41 n = writev(c->fd, iovecs.elts, iovecs.nelts); 41 n = writev(c->fd, io.elts, io.nelts);
42 42
43 if (n == -1) { 43 if (n == -1) {
44 err = ngx_errno; 44 err = ngx_errno;
45 if (err == NGX_EAGAIN) { 45 if (err == NGX_EAGAIN) {
46 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN"); 46 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
60 ngx_log_debug(c->log, "writev: %qd" _ sent); 60 ngx_log_debug(c->log, "writev: %qd" _ sent);
61 #endif 61 #endif
62 62
63 c->sent += sent; 63 c->sent += sent;
64 64
65 for (ce = in; ce && sent > 0; ce = ce->next) { 65 for (cl = in; cl && sent > 0; cl = cl->next) {
66 66
67 size = ce->hunk->last - ce->hunk->pos; 67 size = cl->hunk->last - cl->hunk->pos;
68 68
69 ngx_log_debug(c->log, "SIZE: %d" _ size); 69 ngx_log_debug(c->log, "SIZE: %d" _ size);
70 70
71 if (sent >= size) { 71 if (sent >= size) {
72 sent -= size; 72 sent -= size;
73 73
74 if (ce->hunk->type & NGX_HUNK_IN_MEMORY) { 74 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
75 ce->hunk->pos = ce->hunk->last; 75 cl->hunk->pos = cl->hunk->last;
76 } 76 }
77 77
78 #if 0 78 #if 0
79 if (ce->hunk->type & NGX_HUNK_FILE) { 79 if (cl->hunk->type & NGX_HUNK_FILE) {
80 ce->hunk->file_pos = ce->hunk->file_last; 80 cl->hunk->file_pos = cl->hunk->file_last;
81 } 81 }
82 #endif 82 #endif
83 83
84 continue; 84 continue;
85 } 85 }
86 86
87 if (ce->hunk->type & NGX_HUNK_IN_MEMORY) { 87 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) {
88 ce->hunk->pos += sent; 88 cl->hunk->pos += sent;
89 } 89 }
90 90
91 #if 0 91 #if 0
92 if (ce->hunk->type & NGX_HUNK_FILE) { 92 if (cl->hunk->type & NGX_HUNK_FILE) {
93 ce->hunk->file_pos += sent; 93 cl->hunk->file_pos += sent;
94 } 94 }
95 #endif 95 #endif
96 96
97 break; 97 break;
98 } 98 }
99 99
100 ngx_destroy_array(&iovecs); 100 return cl;
101
102 return ce;
103 } 101 }