From a054f2b968e60f17e591fe988943a2156f61d2a7 Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Tue, 21 Dec 2010 08:38:43 +0100 Subject: [PATCH] various fixes for sendfile() and rack plugin --- plugins/python/pyloader.c | 2 +- plugins/rack/rack_plugin.c | 15 ++++++++------- sendfile.c | 4 +--- utils.c | 12 ++++++++++++ uwsgi.c | 9 ++++----- uwsgi.h | 1 + 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index d03a51c7..073a9805 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -366,7 +366,7 @@ PyObject *uwsgi_mount_loader(void *arg1) { } -/* this is the dynamic loader, it loads app ireading nformation from a wsgi_request */ +/* this is the dynamic loader, it loads app reading information from a wsgi_request */ PyObject *uwsgi_dyn_loader(void *arg1) { PyObject *callable = NULL; diff --git a/plugins/rack/rack_plugin.c b/plugins/rack/rack_plugin.c index b2136f98..dfc12d17 100644 --- a/plugins/rack/rack_plugin.c +++ b/plugins/rack/rack_plugin.c @@ -102,15 +102,15 @@ VALUE rb_uwsgi_io_new(VALUE class, VALUE wr) { return self; } - if (wsgi_req->post_cl > (size_t) uwsgi.post_buffering_bufsize) { - uwsgi_log("using file for http body storage %d\n", wsgi_req->post_cl); + if (wsgi_req->post_cl > (size_t) uwsgi.post_buffering) { + //uwsgi_log("using file for http body storage %d\n", wsgi_req->post_cl); //RUBY_GVL_UNLOCK uwsgi_read_whole_body(wsgi_req, wsgi_req->post_buffering_buf, uwsgi.post_buffering_bufsize); //RUBY_GVL_LOCK } else { //RUBY_GVL_UNLOCK - uwsgi_log("using memory for http body storage %d\n", wsgi_req->post_cl); + //uwsgi_log("using memory for http body storage %d\n", wsgi_req->post_cl); ptr = wsgi_req->post_buffering_buf; while(post_remains > 0) { if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) { @@ -612,12 +612,13 @@ int uwsgi_rack_request(struct wsgi_request *wsgi_req) { if (rb_respond_to( body, rb_intern("to_path") )) { VALUE sendfile_path = rb_funcall( body, rb_intern("to_path"), 0); wsgi_req->sendfile_fd = open(RSTRING_PTR(sendfile_path), O_RDONLY); - uwsgi_log("sendfile_fd_size = %d\n", wsgi_req->sendfile_fd_size); //RUBY_GVL_UNLOCK wsgi_req->response_size = uwsgi_sendfile(wsgi_req); - while(wsgi_req->response_size < wsgi_req->sendfile_fd_size) { - uwsgi_log("sendfile_fd_size = %d\n", wsgi_req->sendfile_fd_size); - wsgi_req->response_size += uwsgi_sendfile(wsgi_req); + if (wsgi_req->response_size > 0) { + while(wsgi_req->response_size < wsgi_req->sendfile_fd_size) { + uwsgi_log("sendfile_fd_size = %d\n", wsgi_req->sendfile_fd_size); + wsgi_req->response_size += uwsgi_sendfile(wsgi_req); + } } //RUBY_GVL_LOCK; rb_gc_unregister_address(&sendfile_path); diff --git a/sendfile.c b/sendfile.c index 4b0d7f12..21aa1048 100644 --- a/sendfile.c +++ b/sendfile.c @@ -11,8 +11,6 @@ ssize_t uwsgi_sendfile(struct wsgi_request *wsgi_req) { struct stat stat_buf; ssize_t sst = 0; - //UWSGI_RELEASE_GIL - if (!wsgi_req->sendfile_fd_size) { if (fstat(fd, &stat_buf)) { @@ -32,7 +30,6 @@ ssize_t uwsgi_sendfile(struct wsgi_request *wsgi_req) { } end: - //UWSGI_GET_GIL return sst; } @@ -73,6 +70,7 @@ ssize_t uwsgi_do_sendfile(int sockfd, int filefd, size_t filesize, size_t chunk, } if (sf_ret) { + uwsgi_log("sf_len = %d\n", sf_len); uwsgi_error("sendfile()"); return 0; } diff --git a/utils.c b/utils.c index fcf9d183..4be13cd2 100644 --- a/utils.c +++ b/utils.c @@ -493,6 +493,18 @@ polling: return -1; } +// in Linux, new sockets do not inherit attributes +#ifndef __linux__ + /* re-set blocking socket */ + int arg = uwsgi.sockets[i].arg ; + arg &= (~O_NONBLOCK); + if (fcntl(wsgi_req->poll.fd, F_SETFL, arg) < 0) { + uwsgi_error("fcntl()"); + return -1; + } + +#endif + if (uwsgi.close_on_exec) { fcntl(wsgi_req->poll.fd, F_SETFD, FD_CLOEXEC); } diff --git a/uwsgi.c b/uwsgi.c index 90484276..eb53ef47 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1066,15 +1066,14 @@ options_parsed: // put listening socket i non-blocking state - int arg; for (i = 0; i < uwsgi.sockets_cnt; i++) { - arg = fcntl(uwsgi.sockets[i].fd, F_GETFL, NULL); - if (arg < 0) { + uwsgi.sockets[i].arg = fcntl(uwsgi.sockets[i].fd, F_GETFL, NULL); + if (uwsgi.sockets[i].arg < 0) { uwsgi_error("fcntl()"); exit(1); } - arg |= O_NONBLOCK; - if (fcntl(uwsgi.sockets[i].fd, F_SETFL, arg) < 0) { + uwsgi.sockets[i].arg |= O_NONBLOCK; + if (fcntl(uwsgi.sockets[i].fd, F_SETFL, uwsgi.sockets[i].arg) < 0) { uwsgi_error("fcntl()"); exit(1); } diff --git a/uwsgi.h b/uwsgi.h index 8b32fa54..24523a19 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -361,6 +361,7 @@ struct uwsgi_socket { char *name; int family; int bound; + int arg; void *ctx; };