Mercurial > hg > nginx
comparison src/os/unix/ngx_writev_chain.c @ 198:34995c5ec6c4
nginx-0.0.1-2003-11-27-22:01:37 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 27 Nov 2003 19:01:37 +0000 |
parents | 8dee38ea9117 |
children | 70e1c7d2b83d |
comparison
equal
deleted
inserted
replaced
197:0b81c7a0b133 | 198:34995c5ec6c4 |
---|---|
8 { | 8 { |
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_int_t eintr; | |
13 ngx_err_t err; | 14 ngx_err_t err; |
14 ngx_array_t io; | 15 ngx_array_t io; |
15 ngx_chain_t *cl; | 16 ngx_chain_t *cl; |
17 ngx_event_t *wev; | |
16 | 18 |
17 if (!c->write->ready) { | 19 wev = c->write; |
20 | |
21 if (!wev->ready) { | |
18 return in; | 22 return in; |
19 } | 23 } |
20 | 24 |
21 ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR); | 25 ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR); |
22 | 26 |
23 prev = NULL; | 27 do { |
24 iov = NULL; | 28 prev = NULL; |
29 iov = NULL; | |
30 eintr = 0; | |
25 | 31 |
26 /* create the iovec and coalesce the neighbouring hunks */ | 32 /* create the iovec and coalesce the neighbouring hunks */ |
27 | 33 |
28 for (cl = in; cl; cl = cl->next) { | 34 for (cl = in; cl; cl = cl->next) { |
29 | 35 |
30 if (prev == cl->hunk->pos) { | 36 if (prev == cl->hunk->pos) { |
31 iov->iov_len += cl->hunk->last - cl->hunk->pos; | 37 iov->iov_len += cl->hunk->last - cl->hunk->pos; |
32 prev = cl->hunk->last; | 38 prev = cl->hunk->last; |
33 | 39 |
34 } else { | 40 } else { |
35 ngx_test_null(iov, ngx_push_array(&io), NGX_CHAIN_ERROR); | 41 ngx_test_null(iov, ngx_push_array(&io), NGX_CHAIN_ERROR); |
36 iov->iov_base = cl->hunk->pos; | 42 iov->iov_base = cl->hunk->pos; |
37 iov->iov_len = cl->hunk->last - cl->hunk->pos; | 43 iov->iov_len = cl->hunk->last - cl->hunk->pos; |
38 prev = cl->hunk->last; | 44 prev = cl->hunk->last; |
45 } | |
39 } | 46 } |
40 } | |
41 | 47 |
42 n = writev(c->fd, io.elts, io.nelts); | 48 n = writev(c->fd, io.elts, io.nelts); |
43 | 49 |
44 if (n == -1) { | 50 if (n == -1) { |
45 err = ngx_errno; | 51 err = ngx_errno; |
46 if (err == NGX_EAGAIN) { | 52 if (err == NGX_EAGAIN) { |
47 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN"); | 53 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN"); |
48 | 54 |
49 } else if (err == NGX_EINTR) { | 55 } else if (err == NGX_EINTR) { |
50 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR"); | 56 eintr = 1; |
57 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR"); | |
51 | 58 |
52 } else { | 59 } else { |
53 ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed"); | 60 wev->error = 1; |
54 return NGX_CHAIN_ERROR; | 61 ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed"); |
62 return NGX_CHAIN_ERROR; | |
63 } | |
55 } | 64 } |
56 } | |
57 | 65 |
58 sent = n > 0 ? n : 0; | 66 sent = n > 0 ? n : 0; |
59 | 67 |
60 #if (NGX_DEBUG_WRITE_CHAIN) | 68 #if (NGX_DEBUG_WRITE_CHAIN) |
61 ngx_log_debug(c->log, "writev: " OFF_T_FMT _ sent); | 69 ngx_log_debug(c->log, "writev: " OFF_T_FMT _ sent); |
62 #endif | 70 #endif |
63 | 71 |
64 c->sent += sent; | 72 c->sent += sent; |
65 | 73 |
66 for (cl = in; cl && sent > 0; cl = cl->next) { | 74 for (cl = in; cl && sent > 0; cl = cl->next) { |
67 | 75 |
68 size = cl->hunk->last - cl->hunk->pos; | 76 size = cl->hunk->last - cl->hunk->pos; |
69 | 77 |
70 ngx_log_debug(c->log, "SIZE: %d" _ size); | 78 ngx_log_debug(c->log, "SIZE: %d" _ size); |
71 | 79 |
72 if (sent >= size) { | 80 if (sent >= size) { |
73 sent -= size; | 81 sent -= size; |
82 | |
83 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { | |
84 cl->hunk->pos = cl->hunk->last; | |
85 } | |
86 | |
87 continue; | |
88 } | |
74 | 89 |
75 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { | 90 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { |
76 cl->hunk->pos = cl->hunk->last; | 91 cl->hunk->pos += sent; |
77 } | 92 } |
78 | 93 |
79 continue; | 94 break; |
80 } | 95 } |
81 | 96 |
82 if (cl->hunk->type & NGX_HUNK_IN_MEMORY) { | 97 } while (eintr); |
83 cl->hunk->pos += sent; | |
84 } | |
85 | 98 |
86 break; | 99 if (cl) { |
100 wev->ready = 0; | |
87 } | 101 } |
88 | 102 |
89 return cl; | 103 return cl; |
90 } | 104 } |