diff options
author | Max Romanov <max.romanov@nginx.com> | 2020-08-17 12:28:48 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2020-08-17 12:28:48 +0300 |
commit | 7ffc617ae89fe08b8a9a17bed41ef8941b8151fb (patch) | |
tree | 3bf66d4e6003ef87514564792edcfa383810b267 | |
parent | 4ac7a6f55fb628e67fec97568e9724719d8a9e0a (diff) | |
download | unit-7ffc617ae89fe08b8a9a17bed41ef8941b8151fb.tar.gz unit-7ffc617ae89fe08b8a9a17bed41ef8941b8151fb.tar.bz2 |
Supporting platforms without sendfile() implementation.
This is a quick and dirty sendfile() replacement.
This closes #452 PR on GitHub.
Diffstat (limited to '')
-rw-r--r-- | auto/sendfile | 6 | ||||
-rw-r--r-- | src/nxt_conn_write.c | 19 |
2 files changed, 20 insertions, 5 deletions
diff --git a/auto/sendfile b/auto/sendfile index a065f7b6..1c20db06 100644 --- a/auto/sendfile +++ b/auto/sendfile @@ -84,10 +84,8 @@ fi if [ $nxt_found = no ]; then - $echo - $echo "$0: error: no supported sendfile() found." - $echo - exit 1; + # No supported sendfile() found. Using our replacement. + nxt_found=yes fi diff --git a/src/nxt_conn_write.c b/src/nxt_conn_write.c index 3e08e43f..bcf9e8fa 100644 --- a/src/nxt_conn_write.c +++ b/src/nxt_conn_write.c @@ -268,7 +268,24 @@ nxt_sendfile(int fd, int s, off_t pos, size_t size) #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 |