comparison src/os/unix/ngx_linux_sendfile_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 11fbd0fc041d
children a65b630b3a66
comparison
equal deleted inserted replaced
197:0b81c7a0b133 198:34995c5ec6c4
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 offset; 11 off_t fprev;
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, *tail; 19 ngx_chain_t *cl, *tail;
20 #if (HAVE_SENDFILE64)
21 off_t offset;
22 #else
23 int32_t offset;
24 #endif
20 25
21 wev = c->write; 26 wev = c->write;
22 27
23 if (!wev->ready) { 28 if (!wev->ready) {
24 return in; 29 return in;
80 85
81 /* get the file hunk */ 86 /* get the file hunk */
82 87
83 file = cl->hunk; 88 file = cl->hunk;
84 fsize = (size_t) (file->file_last - file->file_pos); 89 fsize = (size_t) (file->file_last - file->file_pos);
85 offset = file->file_last; 90 fprev = file->file_last;
86 cl = cl->next; 91 cl = cl->next;
87 92
88 /* coalesce the neighbouring file hunks */ 93 /* coalesce the neighbouring file hunks */
89 94
90 while (cl && (cl->hunk->type & NGX_HUNK_FILE)) { 95 while (cl && (cl->hunk->type & NGX_HUNK_FILE)) {
91 if (file->file->fd != cl->hunk->file->fd 96 if (file->file->fd != cl->hunk->file->fd
92 || offset != cl->hunk->file_pos) 97 || fprev != cl->hunk->file_pos)
93 { 98 {
94 break; 99 break;
95 } 100 }
96 101
97 fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos); 102 fsize += (size_t) (cl->hunk->file_last - cl->hunk->file_pos);
98 offset = cl->hunk->file_last; 103 fprev = cl->hunk->file_last;
99 cl = cl->next; 104 cl = cl->next;
100 } 105 }
101 } 106 }
102 107
103 /* 108 /*
106 */ 111 */
107 112
108 tail = cl; 113 tail = cl;
109 114
110 if (fsize) { 115 if (fsize) {
116 #if (HAVE_SENDFILE64)
111 offset = file->file_pos; 117 offset = file->file_pos;
118 #else
119 offset = (int32_t) file->file_pos;
120 #endif
112 rc = sendfile(c->fd, file->file->fd, &offset, fsize); 121 rc = sendfile(c->fd, file->file->fd, &offset, fsize);
113 122
114 if (rc == -1) { 123 if (rc == -1) {
115 err = ngx_errno; 124 err = ngx_errno;
116 if (err == NGX_EAGAIN) { 125 if (err == NGX_EAGAIN) {