Supporting platforms without sendfile() implementation.

This is a quick and dirty sendfile() replacement.

This closes #452 PR on GitHub.
This commit is contained in:
Max Romanov
2020-08-17 12:28:48 +03:00
parent 4ac7a6f55f
commit 7ffc617ae8
2 changed files with 20 additions and 5 deletions

View File

@@ -84,10 +84,8 @@ fi
if [ $nxt_found = no ]; then if [ $nxt_found = no ]; then
$echo # No supported sendfile() found. Using our replacement.
$echo "$0: error: no supported sendfile() found." nxt_found=yes
$echo
exit 1;
fi fi

View File

@@ -268,7 +268,24 @@ nxt_sendfile(int fd, int s, off_t pos, size_t size)
#else #else
res = -1; int err;
void *map;
off_t page_off;
page_off = pos % nxt_pagesize;
map = nxt_mem_mmap(NULL, size + page_off, PROT_READ, MAP_SHARED, fd,
pos - page_off);
if (nxt_slow_path(map == MAP_FAILED)) {
return -1;
}
res = write(s, nxt_pointer_to(map, page_off), size);
/* Backup and restore errno to catch socket errors in the upper level. */
err = errno;
nxt_mem_munmap(map, size + page_off);
errno = err;
#endif #endif