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 } diff --git a/core/uwsgi.c b/core/uwsgi.c index f131790d..beff3480 100644 --- a/core/uwsgi.c +++ b/core/uwsgi.c @@ -705,6 +705,8 @@ static struct uwsgi_option uwsgi_base_options[] = { {"file-serve-mode", required_argument, 0, "set static file serving mode", uwsgi_opt_fileserve_mode, NULL, UWSGI_OPT_MIME}, {"fileserve-mode", required_argument, 0, "set static file serving mode", uwsgi_opt_fileserve_mode, NULL, UWSGI_OPT_MIME}, + {"disable-sendfile", no_argument, 0, "disable sendfile() and rely on boring read()/write()", uwsgi_opt_true, &uwsgi.disable_sendfile, 0}, + {"check-cache", optional_argument, 0, "check for response data in the specified cache (empty for default cache)", uwsgi_opt_set_str, &uwsgi.use_check_cache, 0}, {"close-on-exec", no_argument, 0, "set close-on-exec on sockets (could be required for spawning processes in requests)", uwsgi_opt_true, &uwsgi.close_on_exec, 0}, {"mode", required_argument, 0, "set uWSGI custom mode", uwsgi_opt_set_str, &uwsgi.mode, 0}, diff --git a/uwsgi.h b/uwsgi.h index 3b7610e3..3a486ed3 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -2037,6 +2037,7 @@ struct uwsgi_server { struct uwsgi_thread **offload_thread; int check_static_docroot; + int disable_sendfile; char *daemonize; char *daemonize2;