Klaus Demo nginx / 906c446
Moved file writev() handling code to a separate function. No functional changes. Valentin Bartenev 6 years ago
1 changed file(s) with 60 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
1212 #include <ngx_thread_pool.h>
1313 static void ngx_thread_read_handler(void *data, ngx_log_t *log);
1414 #endif
15
16 static ssize_t ngx_writev_file(ngx_file_t *file, ngx_array_t *vec, size_t size,
17 off_t offset);
1518
1619
1720 #if (NGX_HAVE_FILE_AIO)
281284 u_char *prev;
282285 size_t size;
283286 ssize_t total, n;
284 ngx_err_t err;
285287 ngx_array_t vec;
286288 struct iovec *iov, iovs[NGX_IOVS];
287289
343345 return total + n;
344346 }
345347
346 if (file->sys_offset != offset) {
347 if (lseek(file->fd, offset, SEEK_SET) == -1) {
348 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
349 "lseek() \"%s\" failed", file->name.data);
350 return NGX_ERROR;
351 }
352
353 file->sys_offset = offset;
354 }
355
356 eintr:
357
358 n = writev(file->fd, vec.elts, vec.nelts);
359
360 if (n == -1) {
361 err = ngx_errno;
362
363 if (err == NGX_EINTR) {
364 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
365 "writev() was interrupted");
366 goto eintr;
367 }
368
369 ngx_log_error(NGX_LOG_CRIT, file->log, err,
370 "writev() \"%s\" failed", file->name.data);
371 return NGX_ERROR;
372 }
373
374 if ((size_t) n != size) {
375 ngx_log_error(NGX_LOG_CRIT, file->log, 0,
376 "writev() \"%s\" has written only %z of %uz",
377 file->name.data, n, size);
378 return NGX_ERROR;
379 }
380
381 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
382 "writev: %d, %z", file->fd, n);
383
384 file->sys_offset += n;
385 file->offset += n;
348 n = ngx_writev_file(file, &vec, size, offset);
349
350 if (n == NGX_ERROR) {
351 return n;
352 }
353
386354 offset += n;
387355 total += n;
388356
389357 } while (cl);
390358
391359 return total;
360 }
361
362
363 static ssize_t
364 ngx_writev_file(ngx_file_t *file, ngx_array_t *vec, size_t size, off_t offset)
365 {
366 ssize_t n;
367 ngx_err_t err;
368
369 if (file->sys_offset != offset) {
370 if (lseek(file->fd, offset, SEEK_SET) == -1) {
371 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
372 "lseek() \"%s\" failed", file->name.data);
373 return NGX_ERROR;
374 }
375
376 file->sys_offset = offset;
377 }
378
379 eintr:
380
381 n = writev(file->fd, vec->elts, vec->nelts);
382
383 if (n == -1) {
384 err = ngx_errno;
385
386 if (err == NGX_EINTR) {
387 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
388 "writev() was interrupted");
389 goto eintr;
390 }
391
392 ngx_log_error(NGX_LOG_CRIT, file->log, err,
393 "writev() \"%s\" failed", file->name.data);
394 return NGX_ERROR;
395 }
396
397 if ((size_t) n != size) {
398 ngx_log_error(NGX_LOG_CRIT, file->log, 0,
399 "writev() \"%s\" has written only %z of %uz",
400 file->name.data, n, size);
401 return NGX_ERROR;
402 }
403
404 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
405 "writev: %d, %z", file->fd, n);
406
407 file->sys_offset += n;
408 file->offset += n;
409
410 return n;
392411 }
393412
394413