comparison src/os/unix/ngx_darwin_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 fddc6bed1e6e
comparison
equal deleted inserted replaced
5916:e044893b4587 5917:2c64b69daec5
31 ngx_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) 31 ngx_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
32 { 32 {
33 int rc; 33 int rc;
34 off_t send, prev_send, sent; 34 off_t send, prev_send, sent;
35 off_t file_size; 35 off_t file_size;
36 ssize_t n;
36 ngx_uint_t eintr; 37 ngx_uint_t eintr;
37 ngx_err_t err; 38 ngx_err_t err;
38 ngx_buf_t *file; 39 ngx_buf_t *file;
39 ngx_event_t *wev; 40 ngx_event_t *wev;
40 ngx_chain_t *cl; 41 ngx_chain_t *cl;
170 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, 171 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
171 "sendfile: %d, @%O %O:%O", 172 "sendfile: %d, @%O %O:%O",
172 rc, file->file_pos, sent, file_size + header.size); 173 rc, file->file_pos, sent, file_size + header.size);
173 174
174 } else { 175 } else {
175 rc = writev(c->fd, header.iovs, header.count); 176 n = ngx_writev(c, &header);
176 177
177 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, 178 if (n == NGX_ERROR) {
178 "writev: %d of %uz", rc, header.size); 179 return NGX_CHAIN_ERROR;
179 180 }
180 if (rc == -1) { 181
181 err = ngx_errno; 182 sent = (n == NGX_AGAIN) ? 0 : n;
182
183 switch (err) {
184 case NGX_EAGAIN:
185 break;
186
187 case NGX_EINTR:
188 eintr = 1;
189 break;
190
191 default:
192 wev->error = 1;
193 ngx_connection_error(c, err, "writev() failed");
194 return NGX_CHAIN_ERROR;
195 }
196
197 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
198 "writev() not ready");
199 }
200
201 sent = rc > 0 ? rc : 0;
202 } 183 }
203 184
204 c->sent += sent; 185 c->sent += sent;
205 186
206 in = ngx_chain_update_sent(in, sent); 187 in = ngx_chain_update_sent(in, sent);