comparison src/os/unix/ngx_linux_sendfile_chain.c @ 253:b6793bc5034b

nginx-0.0.2-2004-02-09-10:46:43 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 09 Feb 2004 07:46:43 +0000
parents 008276b9e061
children 8c5bdde0d9f0
comparison
equal deleted inserted replaced
252:84b1c672ec5a 253:b6793bc5034b
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 5
6 6
7 /* 7 /*
8 * On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit 8 * On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit
9 * offsets only and the including <sys/sendfile.h> breaks the compiling if 9 * offsets only and the including <sys/sendfile.h> breaks the compiling
10 * off_t is 64 bit wide. So we use own sendfile() definition where offset 10 * if off_t is 64 bit wide. So we use own sendfile() definition where offset
11 * parameter is int32_t and use sendfile() with the file parts below 2G. 11 * parameter is int32_t and use sendfile() with the file parts below 2G.
12 * 12 *
13 * Linux 2.4.21 has a new sendfile64() syscall #239. 13 * Linux 2.4.21 has a new sendfile64() syscall #239.
14 */ 14 */
15 15
78 if (!c->tcp_nopush == 0 78 if (!c->tcp_nopush == 0
79 && header.nelts != 0 79 && header.nelts != 0
80 && cl 80 && cl
81 && cl->hunk->type & NGX_HUNK_FILE) 81 && cl->hunk->type & NGX_HUNK_FILE)
82 { 82 {
83 c->tcp_nopush = 1;
84
85 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "tcp_nopush");
86
87 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) { 83 if (ngx_tcp_nopush(c->fd) == NGX_ERROR) {
88 ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno, 84 err = ngx_errno;
89 ngx_tcp_nopush_n " failed"); 85
90 return NGX_CHAIN_ERROR; 86 /*
87 * there is a tiny chance to be interrupted, however
88 * we continue a processing without the TCP_CORK
89 */
90
91 if (err != NGX_EINTR) {
92 wev->error = 1;
93 ngx_connection_error(c, err, ngx_tcp_nopush_n " failed");
94 return NGX_CHAIN_ERROR;
95 }
96
97 } else {
98 c->tcp_nopush = 1;
99 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
100 "tcp_nopush");
91 } 101 }
92 } 102 }
93 103
94 if (header.nelts == 0 && cl && cl->hunk->type & NGX_HUNK_FILE) { 104 if (header.nelts == 0 && cl && cl->hunk->type & NGX_HUNK_FILE) {
95 105
130 #endif 140 #endif
131 rc = sendfile(c->fd, file->file->fd, &offset, fsize); 141 rc = sendfile(c->fd, file->file->fd, &offset, fsize);
132 142
133 if (rc == -1) { 143 if (rc == -1) {
134 err = ngx_errno; 144 err = ngx_errno;
135 if (err == NGX_EAGAIN) { 145
136 ngx_log_error(NGX_LOG_INFO, c->log, err, 146 if (err == NGX_EAGAIN || err == NGX_EINTR) {
137 "sendfile() EAGAIN"); 147 if (err == NGX_EINTR) {
138 148 eintr = 1;
139 } else if (err == NGX_EINTR) { 149 }
140 eintr = 1; 150
141 ngx_log_error(NGX_LOG_INFO, c->log, err, 151 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
142 "sendfile() EINTR"); 152 "sendfile() is not ready");
143 153
144 } else { 154 } else {
145 ngx_log_error(NGX_LOG_CRIT, c->log, err, 155 wev->error = 1;
146 "sendfile() failed"); 156 ngx_connection_error(c, err, "sendfile() failed");
147 return NGX_CHAIN_ERROR; 157 return NGX_CHAIN_ERROR;
148 } 158 }
149 } 159 }
150 160
151 sent = rc > 0 ? rc : 0; 161 sent = rc > 0 ? rc : 0;
152 162
153 #if (NGX_DEBUG_WRITE_CHAIN) 163 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
154 ngx_log_debug(c->log, "sendfile: %d, @" OFF_T_FMT " %d:%d" _ 164 "sendfile: %d, @" OFF_T_FMT " %d:%d",
155 rc _ file->file_pos _ sent _ fsize); 165 rc, file->file_pos, sent, fsize);
156 #endif 166
157 } else { 167 } else {
158 rc = writev(c->fd, header.elts, header.nelts); 168 rc = writev(c->fd, header.elts, header.nelts);
159 169
160 if (rc == -1) { 170 if (rc == -1) {
161 err = ngx_errno; 171 err = ngx_errno;
162 if (err == NGX_EAGAIN) { 172
163 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN"); 173 if (err == NGX_EAGAIN || err == NGX_EINTR) {
164 174 if (err == NGX_EINTR) {
165 } else if (err == NGX_EINTR) { 175 eintr = 1;
166 eintr = 1; 176 }
167 ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR"); 177
178 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
179 "writev() not ready");
168 180
169 } else { 181 } else {
170 ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed"); 182 wev->error = 1;
171 return NGX_CHAIN_ERROR; 183 ngx_connection_error(c, err, "writev() failed");
184 return NGX_CHAIN_ERROR;
172 } 185 }
173 } 186 }
174 187
175 sent = rc > 0 ? rc : 0; 188 sent = rc > 0 ? rc : 0;
176 189
177 #if (NGX_DEBUG_WRITE_CHAIN) 190 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %d", sent);
178 ngx_log_debug(c->log, "writev: %d" _ sent);
179 #endif
180 } 191 }
181 192
182 c->sent += sent; 193 c->sent += sent;
183 194
184 for (cl = in; cl; cl = cl->next) { 195 for (cl = in; cl; cl = cl->next) {