added uwsgi.offload_transfer()

This commit is contained in:
Roberto De Ioris
2012-10-21 18:19:14 +02:00
parent 64c7d71c35
commit 7136beeff7
2 changed files with 41 additions and 0 deletions
+10
View File
@@ -10,6 +10,8 @@ enqueue a file transfer to the offload thread
int uwsgi_offload_request_do(struct wsgi_request *wsgi_req, char *filename, size_t len) {
struct stat st;
// avoid closing the connection
wsgi_req->fd_closed = 1;
@@ -21,6 +23,14 @@ int uwsgi_offload_request_do(struct wsgi_request *wsgi_req, char *filename, size
goto error;
}
uor.s = wsgi_req->poll.fd;
// make a fstat to get the file size
if (!len) {
if (fstat(uor.fd, &st)) {
uwsgi_error("fstat()");
goto error2;
}
len = st.st_size;
}
uor.pos = 0;
uor.len = len;
uor.written = 0;
+31
View File
@@ -783,6 +783,36 @@ PyObject *py_uwsgi_send(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_offload_transfer(PyObject * self, PyObject * args) {
size_t len = 0;
char *filename = NULL;
struct wsgi_request *wsgi_req = current_wsgi_req();
if (!PyArg_ParseTuple(args, "s|i:offload_transfer", &filename, &len)) {
return NULL;
}
if (!wsgi_req->socket->can_offload) {
return PyErr_Format(PyExc_ValueError, "The current socket does not support offloading");
}
if (!wsgi_req->headers_sent) {
if (uwsgi_python_do_send_headers(wsgi_req)) {
return PyErr_Format(PyExc_ValueError, "unable to send headers before offload transfer");
}
}
UWSGI_RELEASE_GIL
if (uwsgi_offload_request_do(wsgi_req, filename, len)) {
UWSGI_GET_GIL
return PyErr_Format(PyExc_ValueError, "Unable to offload the request");
}
UWSGI_GET_GIL
return PyString_FromString("");
}
#ifdef UWSGI_SENDFILE
PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) {
@@ -3179,6 +3209,7 @@ static PyMethodDef uwsgi_advanced_methods[] = {
#ifdef UWSGI_SENDFILE
{"sendfile", py_uwsgi_advanced_sendfile, METH_VARARGS, ""},
#endif
{"offload_transfer", py_uwsgi_offload_transfer, METH_VARARGS, ""},
{"set_warning_message", py_uwsgi_warning, METH_VARARGS, ""},
{"mem", py_uwsgi_mem, METH_VARARGS, ""},
{"has_hook", py_uwsgi_has_hook, METH_VARARGS, ""},