comparison src/os/unix/ngx_linux_sendfile_chain.c @ 5917:2c64b69daec5

Moved writev() handling code to a separate function. This reduces code duplication and unifies debug logging of the writev() syscall among various send chain functions.
author Valentin Bartenev <vbart@nginx.com>
date Wed, 13 Aug 2014 15:11:45 +0400
parents e044893b4587
children c50b5ed3cd4b
comparison
equal deleted inserted replaced
5916:e044893b4587 5917:2c64b69daec5
31 ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) 31 ngx_linux_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
32 { 32 {
33 int rc, tcp_nodelay; 33 int rc, tcp_nodelay;
34 off_t send, prev_send, sent; 34 off_t send, prev_send, sent;
35 size_t file_size; 35 size_t file_size;
36 ssize_t n;
36 ngx_err_t err; 37 ngx_err_t err;
37 ngx_buf_t *file; 38 ngx_buf_t *file;
38 ngx_uint_t eintr; 39 ngx_uint_t eintr;
39 ngx_event_t *wev; 40 ngx_event_t *wev;
40 ngx_chain_t *cl; 41 ngx_chain_t *cl;
197 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, 198 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
198 "sendfile: %d, @%O %O:%uz", 199 "sendfile: %d, @%O %O:%uz",
199 rc, file->file_pos, sent, file_size); 200 rc, file->file_pos, sent, file_size);
200 201
201 } else { 202 } else {
202 rc = writev(c->fd, header.iovs, header.count); 203 n = ngx_writev(c, &header);
203 204
204 if (rc == -1) { 205 if (n == NGX_ERROR) {
205 err = ngx_errno; 206 return NGX_CHAIN_ERROR;
206 207 }
207 switch (err) { 208
208 case NGX_EAGAIN: 209 sent = (n == NGX_AGAIN) ? 0 : n;
209 break;
210
211 case NGX_EINTR:
212 eintr = 1;
213 break;
214
215 default:
216 wev->error = 1;
217 ngx_connection_error(c, err, "writev() failed");
218 return NGX_CHAIN_ERROR;
219 }
220
221 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
222 "writev() not ready");
223 }
224
225 sent = rc > 0 ? rc : 0;
226
227 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "writev: %O", sent);
228 } 210 }
229 211
230 c->sent += sent; 212 c->sent += sent;
231 213
232 in = ngx_chain_update_sent(in, sent); 214 in = ngx_chain_update_sent(in, sent);