Mercurial > hg > nginx
comparison src/os/unix/ngx_readv_chain.c @ 163:fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 28 Oct 2003 15:45:41 +0000 |
parents | 46eb23d9471d |
children | 84036764e215 |
comparison
equal
deleted
inserted
replaced
162:96993d4d5067 | 163:fb61ba77beba |
---|---|
4 #include <ngx_event.h> | 4 #include <ngx_event.h> |
5 | 5 |
6 | 6 |
7 ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) | 7 ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) |
8 { | 8 { |
9 char *prev; | |
9 ssize_t n; | 10 ssize_t n; |
10 struct iovec *iov; | 11 struct iovec *iov; |
11 ngx_err_t err; | 12 ngx_err_t err; |
12 ngx_array_t io; | 13 ngx_array_t io; |
13 | 14 |
14 #if (NGX_SUPPRESS_WARN) | 15 prev = NULL; |
15 iov = NULL; | 16 iov = NULL; |
16 #endif | |
17 | 17 |
18 ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR); | 18 ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR); |
19 | 19 |
20 /* TODO: coalesce the neighbouring chain entries */ | 20 /* coalesce the neighbouring hunks */ |
21 | 21 |
22 while (chain) { | 22 while (chain) { |
23 ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); | 23 if (prev == chain->hunk->last) { |
24 iov->iov_base = chain->hunk->last; | 24 iov->iov_len += chain->hunk->end - chain->hunk->last; |
25 iov->iov_len = chain->hunk->end - chain->hunk->last; | 25 |
26 } else { | |
27 ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); | |
28 iov->iov_base = chain->hunk->last; | |
29 iov->iov_len = chain->hunk->end - chain->hunk->last; | |
30 } | |
31 | |
32 prev = chain->hunk->end; | |
26 chain = chain->next; | 33 chain = chain->next; |
27 } | 34 } |
28 | 35 |
29 ngx_log_debug(c->log, "recv: %d:%d" _ io.nelts _ iov->iov_len); | 36 ngx_log_debug(c->log, "recv: %d:%d" _ io.nelts _ iov->iov_len); |
30 | 37 |
31 n = readv(c->fd, (struct iovec *) io.elts, io.nelts); | 38 n = readv(c->fd, (struct iovec *) io.elts, io.nelts); |
32 | 39 |
33 if (n == -1) { | 40 if (n == 0) { |
41 c->read->eof = 1; | |
42 | |
43 } else if (n == -1) { | |
34 c->read->ready = 0; | 44 c->read->ready = 0; |
45 c->read->error = 1; | |
35 | 46 |
36 err = ngx_errno; | 47 err = ngx_errno; |
37 if (err == NGX_EAGAIN) { | 48 if (err == NGX_EAGAIN) { |
38 ngx_log_error(NGX_LOG_INFO, c->log, err, "readv() returned EAGAIN"); | 49 ngx_log_error(NGX_LOG_INFO, c->log, err, "readv() returned EAGAIN"); |
39 return NGX_AGAIN; | 50 return NGX_AGAIN; |