Klaus Demo nginx / d862ae8
Used the pwritev() syscall for writing files where possible. It is more effective, because it doesn't require a separate lseek(). Valentin Bartenev 6 years ago
2 changed file(s) with 51 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
584584 ngx_feature_path=
585585 ngx_feature_libs=
586586 ngx_feature_test="char buf[1]; ssize_t n; n = pwrite(1, buf, 1, 0);
587 if (n == -1) return 1"
588 . auto/feature
589
590
591 # pwritev() was introduced in FreeBSD 6 and Linux 2.6.30, glibc 2.10
592
593 ngx_feature="pwritev()"
594 ngx_feature_name="NGX_HAVE_PWRITEV"
595 ngx_feature_run=no
596 ngx_feature_incs='#include <sys/uio.h>'
597 ngx_feature_path=
598 ngx_feature_libs=
599 ngx_feature_test="char buf[1]; struct iovec vec[1]; ssize_t n;
600 vec[0].iov_base = buf;
601 vec[0].iov_len = 1;
602 n = pwritev(1, vec, 1, 0);
587603 if (n == -1) return 1"
588604 . auto/feature
589605
366366 ssize_t n;
367367 ngx_err_t err;
368368
369 ngx_log_debug3(NGX_LOG_DEBUG_CORE, file->log, 0,
370 "writev: %d, %uz, %O", file->fd, size, offset);
371
372 #if (NGX_HAVE_PWRITEV)
373
374 eintr:
375
376 n = pwritev(file->fd, vec->elts, vec->nelts, offset);
377
378 if (n == -1) {
379 err = ngx_errno;
380
381 if (err == NGX_EINTR) {
382 ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
383 "pwritev() was interrupted");
384 goto eintr;
385 }
386
387 ngx_log_error(NGX_LOG_CRIT, file->log, err,
388 "pwritev() \"%s\" failed", file->name.data);
389 return NGX_ERROR;
390 }
391
392 if ((size_t) n != size) {
393 ngx_log_error(NGX_LOG_CRIT, file->log, 0,
394 "pwritev() \"%s\" has written only %z of %uz",
395 file->name.data, n, size);
396 return NGX_ERROR;
397 }
398
399 #else
400
369401 if (file->sys_offset != offset) {
370402 if (lseek(file->fd, offset, SEEK_SET) == -1) {
371403 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
401433 return NGX_ERROR;
402434 }
403435
404 ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
405 "writev: %d, %z", file->fd, n);
406
407436 file->sys_offset += n;
437
438 #endif
439
408440 file->offset += n;
409441
410442 return n;