Mercurial > hg > nginx
comparison src/os/unix/ngx_writev_chain.c @ 429:694cd6cdb714
nginx-0.0.11-2004-09-17-20:07:35 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 17 Sep 2004 16:07:35 +0000 |
parents | 744ccb59062d |
children | da8c5707af39 |
comparison
equal
deleted
inserted
replaced
428:5e73d0ea4dab | 429:694cd6cdb714 |
---|---|
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 | 5 |
6 | 6 |
7 #define NGX_IOVS 8 | |
8 | |
9 | |
7 ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) | 10 ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) |
8 { | 11 { |
9 u_char *prev; | 12 u_char *prev; |
10 ssize_t n, size; | 13 ssize_t n, size; |
11 off_t send, sprev, sent; | 14 off_t send, sprev, sent; |
12 struct iovec *iov; | 15 ngx_uint_t eintr, complete; |
13 ngx_uint_t eintr, complete; | 16 ngx_err_t err; |
14 ngx_err_t err; | 17 ngx_array_t vec; |
15 ngx_array_t vec; | 18 ngx_chain_t *cl; |
16 ngx_chain_t *cl; | 19 ngx_event_t *wev; |
17 ngx_event_t *wev; | 20 struct iovec *iov, iovs[NGX_IOVS]; |
18 | 21 |
19 wev = c->write; | 22 wev = c->write; |
20 | 23 |
21 if (!wev->ready) { | 24 if (!wev->ready) { |
22 return in; | 25 return in; |
32 return NGX_CHAIN_ERROR; | 35 return NGX_CHAIN_ERROR; |
33 } | 36 } |
34 | 37 |
35 #endif | 38 #endif |
36 | 39 |
37 ngx_init_array(vec, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR); | |
38 | |
39 send = 0; | 40 send = 0; |
40 complete = 0; | 41 complete = 0; |
42 | |
43 vec.elts = iovs; | |
44 vec.size = sizeof(struct iovec); | |
45 vec.nalloc = NGX_IOVS; | |
46 vec.pool = c->pool; | |
41 | 47 |
42 for ( ;; ) { | 48 for ( ;; ) { |
43 prev = NULL; | 49 prev = NULL; |
44 iov = NULL; | 50 iov = NULL; |
45 eintr = 0; | 51 eintr = 0; |
46 sprev = send; | 52 sprev = send; |
53 | |
54 vec.nelts = 0; | |
47 | 55 |
48 /* create the iovec and coalesce the neighbouring bufs */ | 56 /* create the iovec and coalesce the neighbouring bufs */ |
49 | 57 |
50 for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next) | 58 for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next) |
51 { | 59 { |
61 | 69 |
62 if (prev == cl->buf->pos) { | 70 if (prev == cl->buf->pos) { |
63 iov->iov_len += size; | 71 iov->iov_len += size; |
64 | 72 |
65 } else { | 73 } else { |
66 ngx_test_null(iov, ngx_push_array(&vec), NGX_CHAIN_ERROR); | 74 if (!(iov = ngx_array_push(&vec))) { |
75 return NGX_CHAIN_ERROR; | |
76 } | |
77 | |
67 iov->iov_base = (void *) cl->buf->pos; | 78 iov->iov_base = (void *) cl->buf->pos; |
68 iov->iov_len = size; | 79 iov->iov_len = size; |
69 } | 80 } |
70 | 81 |
71 prev = cl->buf->pos + size; | 82 prev = cl->buf->pos + size; |