diff --git a/core/logging.c b/core/logging.c index 2f107f33..909c1c70 100644 --- a/core/logging.c +++ b/core/logging.c @@ -601,16 +601,19 @@ void uwsgi_logit_simple(struct wsgi_request *wsgi_req) { } } - if (wsgi_req->sendfile_fd > -1 && wsgi_req->sendfile_obj == wsgi_req->async_result) { //wsgi_req->sendfile_fd_size > 0 ) { - via = msg1; - } - - // mark route() requests - if (wsgi_req->status == -17) { - via = msg3; - } - else if (wsgi_req->status == -30) { - via = msg4; + // mark requests via (sendfile, route, offload...) + switch(wsgi_req->via) { + case UWSGI_VIA_SENDFILE: + via = msg1; + break; + case UWSGI_VIA_ROUTE: + via = msg3; + break; + case UWSGI_VIA_OFFLOAD: + via = msg4; + break; + default: + break; } #ifdef __sun__ diff --git a/core/offload.c b/core/offload.c index 2bd48294..ff2a84a0 100644 --- a/core/offload.c +++ b/core/offload.c @@ -70,16 +70,21 @@ error: return -1; } -int uwsgi_offload_request_sendfile_do(struct wsgi_request *wsgi_req, char *filename, size_t len) { +int uwsgi_offload_request_sendfile_do(struct wsgi_request *wsgi_req, char *filename, int fd, size_t len) { // fill offload request struct uwsgi_offload_request uor; uwsgi_offload_setup(&uor, wsgi_req, uwsgi_offload_sendfile_transfer); - uor.fd = open(filename, O_RDONLY | O_NONBLOCK); - if (uor.fd < 0) { - uwsgi_error_open(filename); - goto error; + if (filename) { + uor.fd = open(filename, O_RDONLY | O_NONBLOCK); + if (uor.fd < 0) { + uwsgi_error_open(filename); + goto error; + } + } + else { + uor.fd = fd; } // make a fstat to get the file size diff --git a/core/protocol.c b/core/protocol.c index 49561915..d0583659 100644 --- a/core/protocol.c +++ b/core/protocol.c @@ -839,7 +839,6 @@ next: // read to disk if post_cl > post_buffering (it will eventually do upload progress...) if (wsgi_req->post_cl >= (size_t) uwsgi.post_buffering) { if (!uwsgi_read_whole_body(wsgi_req, wsgi_req->post_buffering_buf, uwsgi.post_buffering_bufsize)) { - wsgi_req->status = -1; return -1; } wsgi_req->body_as_file = 1; @@ -847,7 +846,6 @@ next: // on tiny post use memory else { if (!uwsgi_read_whole_body_in_mem(wsgi_req, wsgi_req->post_buffering_buf)) { - wsgi_req->status = -1; return -1; } } @@ -861,7 +859,6 @@ next: if (cache_value && cache_value_size > 0) { uwsgi_response_write_body_do(wsgi_req, cache_value, cache_value_size); free(cache_value); - wsgi_req->status = -1; return -1; } } @@ -873,7 +870,6 @@ next: if (cache_value && cache_value_size > 0) { uwsgi_response_write_body_do(wsgi_req, cache_value, cache_value_size); free(cache_value); - wsgi_req->status = -1; return -1; } } diff --git a/core/static.c b/core/static.c index 6b9d4f7e..01226ef0 100644 --- a/core/static.c +++ b/core/static.c @@ -442,8 +442,9 @@ int uwsgi_real_file_serve(struct wsgi_request *wsgi_req, char *real_filename, si // Ok, the file must be transferred from uWSGI if (wsgi_req->socket->can_offload) { - if (!uwsgi_offload_request_sendfile_do(wsgi_req, real_filename, st->st_size)) { - wsgi_req->status = -30; + if (!uwsgi_offload_request_sendfile_do(wsgi_req, real_filename, -1, st->st_size)) { + wsgi_req->via = UWSGI_VIA_OFFLOAD; + wsgi_req->response_size += st->st_size; return 0; } } diff --git a/core/writer.c b/core/writer.c index cd049add..5350bd94 100644 --- a/core/writer.c +++ b/core/writer.c @@ -203,6 +203,17 @@ sendfile: len = st.st_size; } + if (wsgi_req->socket->can_offload) { + if (!uwsgi_offload_request_sendfile_do(wsgi_req, NULL, fd, len)) { + wsgi_req->via = UWSGI_VIA_OFFLOAD; + wsgi_req->response_size += len; + return 0; + } + } + + + wsgi_req->via = UWSGI_VIA_SENDFILE; + for(;;) { int ret = wsgi_req->socket->proto_sendfile(wsgi_req, fd, pos, len); if (ret < 0) { diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index b10d87ba..e083e3d9 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -820,7 +820,7 @@ PyObject *py_uwsgi_offload_transfer(PyObject * self, PyObject * args) { UWSGI_RELEASE_GIL - if (uwsgi_offload_request_sendfile_do(wsgi_req, filename, len)) { + if (uwsgi_offload_request_sendfile_do(wsgi_req, filename, -1, len)) { UWSGI_GET_GIL return PyErr_Format(PyExc_ValueError, "unable to offload the request"); } @@ -2681,7 +2681,7 @@ PyObject *py_uwsgi_route(PyObject * self, PyObject * args) { ui->func = NULL; // mark a route request - wsgi_req->status = -17; + wsgi_req->via = UWSGI_VIA_ROUTE; return (PyObject *) ui; } diff --git a/plugins/router_http/router_http.c b/plugins/router_http/router_http.c index b07829f3..444a17b8 100644 --- a/plugins/router_http/router_http.c +++ b/plugins/router_http/router_http.c @@ -7,7 +7,7 @@ extern struct uwsgi_server uwsgi; int uwsgi_routing_func_http(struct wsgi_request *wsgi_req, struct uwsgi_route *ur) { // mark a route request - wsgi_req->status = -17; + wsgi_req->via = UWSGI_VIA_ROUTE; // get the http address from the route char *addr = ur->data; @@ -33,7 +33,7 @@ int uwsgi_routing_func_http(struct wsgi_request *wsgi_req, struct uwsgi_route *u // ok now if have offload threads, directly use them if (wsgi_req->socket->can_offload) { if (!uwsgi_offload_request_net_do(wsgi_req, addr, ub)) { - wsgi_req->status = -30; + wsgi_req->via = UWSGI_VIA_OFFLOAD; return UWSGI_ROUTE_BREAK; } } diff --git a/plugins/router_uwsgi/router_uwsgi.c b/plugins/router_uwsgi/router_uwsgi.c index 9f4755fc..076fccad 100644 --- a/plugins/router_uwsgi/router_uwsgi.c +++ b/plugins/router_uwsgi/router_uwsgi.c @@ -37,7 +37,7 @@ int uwsgi_routing_func_uwsgi_remote(struct wsgi_request *wsgi_req, struct uwsgi_ char *addr = ur->data + sizeof(struct uwsgi_header); // mark a route request - wsgi_req->status = -17; + wsgi_req->via = UWSGI_VIA_ROUTE; // append appid if (ur->data2_len > 0) { @@ -52,7 +52,7 @@ int uwsgi_routing_func_uwsgi_remote(struct wsgi_request *wsgi_req, struct uwsgi_ if (uwsgi_buffer_append(ub, (char *) uh, 4)) goto bad; if (uwsgi_buffer_append(ub, wsgi_req->buffer, uh->pktsize)) goto bad; if (!uwsgi_offload_request_net_do(wsgi_req, addr, ub)) { - wsgi_req->status = -30; + wsgi_req->via = UWSGI_VIA_OFFLOAD; return UWSGI_ROUTE_BREAK; } bad: diff --git a/uwsgi.h b/uwsgi.h index 528df618..a464d629 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -66,6 +66,10 @@ extern "C" { #define MAX_PROBES 64 #define MAX_CRONS 64 +#define UWSGI_VIA_SENDFILE 1 +#define UWSGI_VIA_ROUTE 2 +#define UWSGI_VIA_OFFLOAD 3 + #ifndef UWSGI_LOAD_EMBEDDED_PLUGINS #define UWSGI_LOAD_EMBEDDED_PLUGINS #endif @@ -1162,6 +1166,8 @@ struct wsgi_request { char *authorization; uint16_t authorization_len; + uint16_t via; + char *script; uint16_t script_len; char *module; @@ -3688,7 +3694,7 @@ struct uwsgi_offload_request { }; struct uwsgi_thread *uwsgi_offload_thread_start(void); -int uwsgi_offload_request_sendfile_do(struct wsgi_request *, char *, size_t); +int uwsgi_offload_request_sendfile_do(struct wsgi_request *, char *, int, size_t); int uwsgi_offload_request_net_do(struct wsgi_request *, char *, struct uwsgi_buffer *); void uwsgi_subscription_set_algo(char *);