summaryrefslogtreecommitdiffhomepage
path: root/src/os/unix/ngx_darwin_sendfile_chain.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2017-01-20Fixed trailer construction with limit on FreeBSD and macOS.Maxim Dounin1-1/+1
The ngx_chain_coalesce_file() function may produce more bytes to send then requested in the limit passed, as it aligns the last file position to send to memory page boundary. As a result, (limit - send) may become negative. This resulted in big positive number when converted to size_t while calling ngx_output_chain_to_iovec(). Another part of the problem is in ngx_chain_coalesce_file(): it changes cl to the next chain link even if the current buffer is only partially sent due to limit. Therefore, if a file buffer was not expected to be fully sent due to limit, and was followed by a memory buffer, nginx called sendfile() with a part of the file buffer, and the memory buffer in trailer. If there were enough room in the socket buffer, this resulted in a part of the file buffer being skipped, and corresponding part of the memory buffer sent instead. The bug was introduced in 8e903522c17a (1.7.8). Configurations affected are ones using limits, that is, limit_rate and/or sendfile_max_chunk, and memory buffers after file ones (may happen when using subrequests or with proxying with disk buffering). Fix is to explicitly check if (send < limit) before constructing trailer with ngx_output_chain_to_iovec(). Additionally, ngx_chain_coalesce_file() was modified to preserve unfinished file buffers in cl.
2015-01-13Fixed sendfile() trailers on OS X (8e903522c17a, 1.7.8).Maxim Dounin1-0/+3
The trailer.count variable was not initialized if there was a header, resulting in "sendfile() failed (22: Invalid argument)" alerts on OS X if the "sendfile" directive was used. The bug was introduced in 8e903522c17a (1.7.8).
2014-11-19Style.Valentin Bartenev1-2/+2
2014-08-13Moved writev() handling code to a separate function.Valentin Bartenev1-24/+5
This reduces code duplication and unifies debug logging of the writev() syscall among various send chain functions.
2014-08-13Merged conditions in the ngx_*_sendfile_chain() functions.Valentin Bartenev1-13/+10
No functional changes.
2014-08-13Moved the code for coalescing file buffers to a separate function.Valentin Bartenev1-24/+3
2014-10-07Introduced the ngx_output_chain_to_iovec() function.Valentin Bartenev1-102/+24
It deduplicates code of the send chain functions and uses only preallocated memory, which completely solves the problem mentioned in d1bde5c3c5d2.
2014-11-19Renamed ngx_handle_sent_chain() to ngx_chain_update_sent().Valentin Bartenev1-1/+1
No functional changes.
2014-08-27Fixed counting of sent bytes in the send chain functions on EINTR.Valentin Bartenev1-0/+1
Previously, a value of the "send" variable wasn't properly adjusted in a rare case when syscall was interrupted by a signal. As a result, these functions could send less data than the limit allows.
2014-08-13Generalized definitions of the number of preallocated iovec's.Valentin Bartenev1-12/+5
No functional changes.
2014-08-13Removed the "complete" variable from various send chain functions.Valentin Bartenev1-7/+2
It was made redundant by the previous change, since the "sent" variable is no longer modified.
2014-08-13Moved the code for adjusting sent buffers in a separate function.Valentin Bartenev1-36/+1
2014-08-13Fixed writev() debug log message in ngx_darwin_sendfile_chain().Valentin Bartenev1-1/+1
2014-06-19FreeBSD has migrated to Bugzilla.Sergey Kandaurov1-1/+1
2013-08-08Don't lose pointer to first nonempty buf in ngx_*_sendfile_chain().Gleb Smirnoff1-16/+14
In ngx_*_sendfile_chain() when calculating pointer to a first non-zero sized buf, use "in" as iterator. This fixes processing of zero sized buf(s) after EINTR. Otherwise function can return zero sized buf to caller, and later ngx_http_write_filter() logs warning.
2012-04-17IOV_MAX handling microoptimization.Maxim Dounin1-5/+11
We now stop on IOV_MAX iovec entries only if we are going to add new one, i.e. next buffer can't be coalesced into last iovec. This also fixes incorrect checks for trailer creation on FreeBSD and Mac OS X, header.nelts was checked instead of trailer.nelts.
2012-02-28Fixed spelling in single-line comments.Ruslan Ermilov1-1/+1
2012-01-18Copyright updated.Maxim Konovalov1-0/+1
2009-08-30refactor EAGAIN/EINTR processingIgor Sysoev1-19/+21
2008-07-30*) move Darwin support to separate filesIgor Sysoev1-0/+363
*) Darwin sendfile() support