various test for trying to allow pre-connected requests

This commit is contained in:
roberto@sirius
2010-12-11 20:08:23 +01:00
parent 96700a49e3
commit 245ab6d815
12 changed files with 320 additions and 16 deletions
+2
View File
@@ -27,6 +27,8 @@ PyObject *python_call(PyObject *callable, PyObject *args, int catch) {
}
#endif
uwsgi_log("python called\n");
return pyret;
}
+18 -5
View File
@@ -7,8 +7,6 @@ char *spool_buffer = NULL;
extern struct uwsgi_server uwsgi;
extern struct uwsgi_python up;
#define UWSGI_LOGBASE "[- uWSGI -"
char *uwsgi_encode_pydict(PyObject *pydict, uint16_t *size) {
int i;
@@ -38,20 +36,17 @@ char *uwsgi_encode_pydict(PyObject *pydict, uint16_t *size) {
if (!PyTuple_Check(zero)) {
uwsgi_log("invalid python dictionary item\n");
Py_DECREF(zero);
continue;
}
if (PyTuple_Size(zero) < 2) {
uwsgi_log("invalid python dictionary item\n");
Py_DECREF(zero);
continue;
}
key = PyTuple_GetItem(zero, 0);
val = PyTuple_GetItem(zero, 1);
if (!PyString_Check(key) || !PyString_Check(val)) {
Py_DECREF(zero);
continue;
}
@@ -100,6 +95,11 @@ char *uwsgi_encode_pydict(PyObject *pydict, uint16_t *size) {
key = PyTuple_GetItem(zero, 0);
val = PyTuple_GetItem(zero, 1);
if (!key || !val) {
PyErr_Print();
}
if (!PyString_Check(key) || !PyString_Check(val)) {
Py_DECREF(zero);
continue;
@@ -1155,6 +1155,7 @@ PyObject* uwsgi_Iter_next(PyObject *self) {
char buf[4096];
UWSGI_RELEASE_GIL
uwsgi_log("waiting for data\n");
rlen = uwsgi_waitfd(ui->fd, ui->timeout);
if (rlen > 0) {
rlen = read(ui->fd, buf, 4096);
@@ -1212,6 +1213,16 @@ static PyTypeObject uwsgi_IterType = {
};
PyObject *py_uwsgi_connect(PyObject * self, PyObject * args) {
char *socket_name = NULL;
if (!PyArg_ParseTuple(args, "s:connect", &socket_name)) {
return NULL;
}
return PyInt_FromLong(uwsgi_connect(socket_name, 0, 0));
}
PyObject *py_uwsgi_async_connect(PyObject * self, PyObject * args) {
char *socket_name = NULL;
@@ -1795,6 +1806,8 @@ static PyMethodDef uwsgi_advanced_methods[] = {
{"wait_fd_read", py_eventfd_read, METH_VARARGS, ""},
{"wait_fd_write", py_eventfd_write, METH_VARARGS, ""},
#endif
{"connect", py_uwsgi_connect, METH_VARARGS, ""},
{"is_connected", py_uwsgi_is_connected, METH_VARARGS, ""},
{"send", py_uwsgi_send, METH_VARARGS, ""},
{"recv", py_uwsgi_recv, METH_VARARGS, ""},
+5 -3
View File
@@ -274,8 +274,10 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
}
}
if (wsgi_req->uh.modifier2 == 4) {
// for persistent connections
wsgi_req->leave_open = 1;
}
if (uwsgi.post_buffering > 0 && wsgi_req->post_cl > (size_t) uwsgi.post_buffering) {
@@ -285,7 +287,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
}
UWSGI_GET_GIL
}
else {
else if (!wsgi_req->leave_open) {
wsgi_req->async_post = fdopen(wsgi_req->poll.fd, "r");
}
+10 -1
View File
@@ -15,6 +15,7 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_
}
*/
wsgi_socket = PyFile_FromFile(wsgi_req->async_post, "wsgi_input", "r", NULL);
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.input", wsgi_socket);
Py_DECREF(wsgi_socket);
@@ -125,6 +126,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
goto clear;
}
#ifdef UWSGI_SENDFILE
if (wsgi_req->sendfile_obj == wsgi_req->async_result && wsgi_req->sendfile_fd != -1) {
sf_len = uwsgi_sendfile(wsgi_req);
@@ -142,6 +144,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
}
#endif
// ok its a yield
if (!wsgi_req->async_placeholder) {
wsgi_req->async_placeholder = PyObject_GetIter(wsgi_req->async_result);
@@ -158,6 +161,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
pychunk = PyIter_Next(wsgi_req->async_placeholder);
if (!pychunk) {
@@ -167,6 +171,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
if (PyString_Check(pychunk)) {
if ((wsize = write(wsgi_req->poll.fd, PyString_AsString(pychunk), PyString_Size(pychunk))) < 0) {
uwsgi_error("write()");
@@ -184,11 +189,13 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
}
#endif
Py_DECREF(pychunk);
UWSGI_RELEASE_GIL
return UWSGI_AGAIN;
clear:
if (wsgi_req->sendfile_fd != -1) {
Py_DECREF((PyObject *)wsgi_req->async_sendfile);
}
@@ -196,7 +203,9 @@ clear:
PyDict_Clear(wsgi_req->async_environ);
}
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
fclose(wsgi_req->async_post);
if (!wsgi_req->leave_open) {
fclose(wsgi_req->async_post);
}
if (!uwsgi.post_buffering || wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) {
wsgi_req->fd_closed = 1;
}