Mercurial > hg > nginx
comparison src/os/unix/ngx_linux_sendfile_chain.c @ 196:11fbd0fc041d
nginx-0.0.1-2003-11-26-18:42:18 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 26 Nov 2003 15:42:18 +0000 |
parents | 8dee38ea9117 |
children | 34995c5ec6c4 |
comparison
equal
deleted
inserted
replaced
195:8dee38ea9117 | 196:11fbd0fc041d |
---|---|
6 | 6 |
7 ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in) | 7 ngx_chain_t *ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in) |
8 { | 8 { |
9 int rc; | 9 int rc; |
10 char *prev; | 10 char *prev; |
11 off_t fprev; | 11 off_t offset; |
12 size_t size, fsize, sent; | 12 size_t size, fsize, sent; |
13 ngx_int_t use_cork, eintr; | 13 ngx_int_t use_cork, eintr; |
14 struct iovec *iov; | 14 struct iovec *iov; |
15 ngx_err_t err; | 15 ngx_err_t err; |
16 ngx_hunk_t *file; | 16 ngx_hunk_t *file; |
17 ngx_array_t header; | 17 ngx_array_t header; |
18 ngx_event_t *wev; | 18 ngx_event_t *wev; |
19 ngx_chain_t *cl; | 19 ngx_chain_t *cl, *tail; |
20 | 20 |
21 wev = c->write; | 21 wev = c->write; |
22 | 22 |
23 if (!wev->ready) { | 23 if (!wev->ready) { |
24 return in; | 24 return in; |
25 } | 25 } |
26 | |
27 cork = 0; | |
28 | 26 |
29 do { | 27 do { |
30 file = NULL; | 28 file = NULL; |
31 fsize = 0; | 29 fsize = 0; |
32 eintr = 0; | 30 eintr = 0; |
82 | 80 |
83 /* get the file hunk */ | 81 /* get the file hunk */ |
84 | 82 |
85 file = cl->hunk; | 83 file = cl->hunk; |
86 fsize = (size_t) (file->file_last - file->file_pos); | 84 fsize = (size_t) (file->file_last - file->file_pos); |
87 fprev = file->file_last; | 85 offset = file->file_last; |
88 cl = cl->next; | 86 cl = cl->next; |
89 | 87 |
90 /* coalesce the neighbouring file hunks */ | 88 /* coalesce the neighbouring file hunks */ |
91 | 89 |
92 while (cl && (cl->hunk->type & NGX_HUNK_FILE)) { | 90 while (cl && (cl->hunk->type & NGX_HUNK_FILE)) { |
93 if (file->file->fd != cl->hunk->file->fd | 91 if (file->file->fd != cl->hunk->file->fd |
94 || fprev != cl->hunk->file_pos) | 92 || offset != cl->hunk->file_pos) |
95 { | 93 { |
96 break; | 94 break; |
97 } | 95 } |
98 | 96 |
99 fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos); | 97 fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos); |
100 fprev = cl->hunk->file_last; | 98 offset = cl->hunk->file_last; |
101 cl = cl->next; | 99 cl = cl->next; |
102 } | 100 } |
103 } | 101 } |
104 | 102 |
105 /* | 103 /* |
108 */ | 106 */ |
109 | 107 |
110 tail = cl; | 108 tail = cl; |
111 | 109 |
112 if (fsize) { | 110 if (fsize) { |
113 rc = sendfile(c->fd, file->file->fd, file->file_pos, fsize); | 111 offset = file->file_pos; |
112 rc = sendfile(c->fd, file->file->fd, &offset, fsize); | |
114 | 113 |
115 if (rc == -1) { | 114 if (rc == -1) { |
116 err = ngx_errno; | 115 err = ngx_errno; |
117 if (err == NGX_EAGAIN) { | 116 if (err == NGX_EAGAIN) { |
118 ngx_log_error(NGX_LOG_INFO, c->log, err, | 117 ngx_log_error(NGX_LOG_INFO, c->log, err, |