diff options
author | Unbit <info@unbit.it> | 2013-09-02 15:55:02 +0200 |
---|---|---|
committer | Unbit <info@unbit.it> | 2013-09-02 15:55:02 +0200 |
commit | b489fd8a24a4c548332e8a560a69d346ef690f36 (patch) | |
tree | d8dd9278c883aef5502c4740b7ed8734b4ba5423 /core/sendfile.c | |
parent | a33e18b589c5f4001e44b8426fad048b0c23ac3f (diff) | |
download | uwsgi-b489fd8a24a4c548332e8a560a69d346ef690f36.tar.gz |
added --disable-sendfile
Diffstat (limited to 'core/sendfile.c')
-rw-r--r-- | core/sendfile.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/core/sendfile.c b/core/sendfile.c index 17ecd5e2..88e01234 100644 --- a/core/sendfile.c +++ b/core/sendfile.c @@ -4,6 +4,11 @@ extern struct uwsgi_server uwsgi; // sendfile() abstraction ssize_t uwsgi_sendfile_do(int sockfd, int filefd, size_t pos, size_t len) { + // for platform not supporting sendfile we need to rely on boring read/write + // generally that platforms have very low memory, so use a 8k buffer + char buf[8192]; + + if (uwsgi.disable_sendfile) goto no_sendfile; #if defined(__FreeBSD__) || defined(__DragonFly__) off_t sf_len = len; @@ -18,12 +23,11 @@ ssize_t uwsgi_sendfile_do(int sockfd, int filefd, size_t pos, size_t len) { #elif defined(__linux__) || defined(__sun__) off_t off = pos; return sendfile(sockfd, filefd, &off, len); -#else - // for platform not supporting sendfile we need to rely on boring read/write - // generally that platforms have very low memory, so use a 8k buffer - char buf[8192]; +#endif + +no_sendfile: if (pos > 0) { - if (lseek(filefd, pos, SEEK_SET)) { + if (lseek(filefd, pos, SEEK_SET) < 0) { uwsgi_error("uwsgi_sendfile_do()/seek()"); return -1; } @@ -34,7 +38,6 @@ ssize_t uwsgi_sendfile_do(int sockfd, int filefd, size_t pos, size_t len) { return -1; } return write(sockfd, buf, rlen); -#endif } |