From d6b4b8ea6eadc6c1a5c8c31669d0dcedb07e29e5 Mon Sep 17 00:00:00 2001 From: Roberto De Ioris Date: Tue, 23 Oct 2012 20:44:01 +0200 Subject: [PATCH] improved wsgi.input reports --- plugins/gevent/gevent.c | 9 ++++----- plugins/python/uwsgi_python.h | 4 ++-- plugins/python/wsgi_handlers.c | 18 ++++++++---------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/plugins/gevent/gevent.c b/plugins/gevent/gevent.c index 7b52cee3..251c5c19 100644 --- a/plugins/gevent/gevent.c +++ b/plugins/gevent/gevent.c @@ -206,9 +206,8 @@ clear: return Py_None; } -ssize_t uwsgi_gevent_hook_input_read(struct wsgi_request *wsgi_req, char *tmp_buf, size_t remains) { +ssize_t uwsgi_gevent_hook_input_read(struct wsgi_request *wsgi_req, char *tmp_buf, size_t remains, size_t *tmp_pos) { - size_t tmp_pos = 0; /// create a watcher for reads PyObject *watcher = PyObject_CallMethod(ugevent.hub_loop, "io", "ii", wsgi_req->poll.fd, 1); if (!watcher) return -1; @@ -252,19 +251,19 @@ ssize_t uwsgi_gevent_hook_input_read(struct wsgi_request *wsgi_req, char *tmp_bu } UWSGI_RELEASE_GIL; - ssize_t rlen = read(wsgi_req->poll.fd, tmp_buf+tmp_pos, remains); + ssize_t rlen = read(wsgi_req->poll.fd, tmp_buf+*tmp_pos, remains); if (rlen <= 0) { UWSGI_GET_GIL stop_the_watchers_and_clear return -1; } - tmp_pos += rlen; + *tmp_pos += rlen; remains -= rlen; UWSGI_GET_GIL stop_the_watchers } - return tmp_pos; + return *tmp_pos; } diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index efd21a2c..993b30ae 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -187,7 +187,7 @@ struct uwsgi_python { int start_response_nodelay; void (*hook_write_string)(struct wsgi_request *, PyObject *); - ssize_t (*hook_wsgi_input_read)(struct wsgi_request *, char *, size_t); + ssize_t (*hook_wsgi_input_read)(struct wsgi_request *, char *, size_t, size_t *); ssize_t (*hook_wsgi_input_readline)(struct wsgi_request *, char *, size_t); char *programname; @@ -281,7 +281,7 @@ int uwsgi_python_do_send_headers(struct wsgi_request *); void *uwsgi_python_tracebacker_thread(void *); PyObject *uwsgi_python_setup_thread(char *); -ssize_t uwsgi_python_hook_simple_input_read(struct wsgi_request *, char *, size_t); +ssize_t uwsgi_python_hook_simple_input_read(struct wsgi_request *, char *, size_t, size_t *); ssize_t uwsgi_python_hook_simple_input_readline(struct wsgi_request *, char *, size_t); #ifdef UWSGI_PYPY diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index 362a6e25..1f5f3d86 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -98,9 +98,7 @@ static void uwsgi_Input_free(uwsgi_Input *self) { PyObject_Del(self); } -ssize_t uwsgi_python_hook_simple_input_read(struct wsgi_request *wsgi_req, char *tmp_buf, size_t remains) { - - size_t tmp_pos = 0; +ssize_t uwsgi_python_hook_simple_input_read(struct wsgi_request *wsgi_req, char *tmp_buf, size_t remains, size_t *tmp_pos) { UWSGI_RELEASE_GIL @@ -110,17 +108,17 @@ ssize_t uwsgi_python_hook_simple_input_read(struct wsgi_request *wsgi_req, char return 0; } - ssize_t rlen = read(wsgi_req->poll.fd, tmp_buf+tmp_pos, remains); + ssize_t rlen = read(wsgi_req->poll.fd, tmp_buf+*tmp_pos, remains); if (rlen <= 0) { UWSGI_GET_GIL return -1; } - tmp_pos += rlen; + *tmp_pos += rlen; remains -= rlen; } UWSGI_GET_GIL - return tmp_pos; + return *tmp_pos; } @@ -128,7 +126,7 @@ static PyObject *uwsgi_Input_read(uwsgi_Input *self, PyObject *args) { long len = 0; size_t remains; - ssize_t tmp_pos = 0; + size_t tmp_pos = 0; char *tmp_buf; PyObject *res; @@ -179,10 +177,10 @@ static PyObject *uwsgi_Input_read(uwsgi_Input *self, PyObject *args) { tmp_buf = uwsgi_malloc(remains); - tmp_pos = up.hook_wsgi_input_read(self->wsgi_req, tmp_buf, remains); - if (tmp_pos < 0) { + ssize_t rlen = up.hook_wsgi_input_read(self->wsgi_req, tmp_buf, remains, &tmp_pos); + if (rlen < 0) { free(tmp_buf); - return PyErr_Format(PyExc_IOError, "error reading for wsgi.input data: Content-Length %llu requested %llu received %llu", (unsigned long long) self->wsgi_req->post_cl, (unsigned long long) (remains + (tmp_pos+1)), (unsigned long long) (tmp_pos+1)); + return PyErr_Format(PyExc_IOError, "error reading for wsgi.input data: Content-Length %llu requested %llu received %llu", (unsigned long long) self->wsgi_req->post_cl, (unsigned long long) (remains + tmp_pos), (unsigned long long) tmp_pos); } else if (tmp_pos == 0) { free(tmp_buf);