From 61793201c788269958e13696a14b19de26c8ca76 Mon Sep 17 00:00:00 2001 From: "roberto@goyle" Date: Wed, 22 Jun 2011 11:14:02 +0200 Subject: [PATCH] fixed uwsgi.sendfile in threading mode --- plugins/python/uwsgi_pymodule.c | 5 +++-- sendfile.c | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index f50463dc..46165ff2 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -758,6 +758,7 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { off_t pos = 0; size_t filesize = 0; struct stat stat_buf; + struct wsgi_request *wsgi_req = current_wsgi_req(); int fd = -1; @@ -782,7 +783,7 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { goto clear; // check for mixing file_wrapper and sendfile - if (fd == uwsgi.wsgi_req->sendfile_fd) { + if (fd == wsgi_req->sendfile_fd) { Py_INCREF(what); } } @@ -804,7 +805,7 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { if (!chunk) chunk = 4096; - uwsgi.wsgi_req->response_size += uwsgi_do_sendfile(uwsgi.wsgi_req->poll.fd, fd, filesize, chunk, &pos, 0); + uwsgi.wsgi_req->response_size += uwsgi_do_sendfile(wsgi_req->poll.fd, fd, filesize, chunk, &pos, 0); close(fd); Py_INCREF(Py_True); diff --git a/sendfile.c b/sendfile.c index fdbef7b5..5c1fd663 100644 --- a/sendfile.c +++ b/sendfile.c @@ -72,11 +72,14 @@ ssize_t uwsgi_do_sendfile(int sockfd, int filefd, size_t filesize, size_t chunk, *pos += sf_len; } else { + uwsgi_log("%d %d\n", filefd, sockfd); sf_ret = sendfile(filefd, sockfd, 0, &sf_len, NULL, 0); } if (sf_ret) { +#ifdef UWSGI_DEBUG uwsgi_log("sf_len = %d\n", sf_len); +#endif uwsgi_error("sendfile()"); return 0; }