mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 21:51:30 +00:00
implemented reliable gevent non-blocking writes
This commit is contained in:
@@ -9,6 +9,12 @@ extern struct http_status_codes hsc[];
|
||||
|
||||
extern PyTypeObject uwsgi_InputType;
|
||||
|
||||
void python_simple_hook_write_string(struct wsgi_request *wsgi_req, PyObject *str) {
|
||||
UWSGI_RELEASE_GIL
|
||||
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(str), PyString_Size(str));
|
||||
UWSGI_GET_GIL
|
||||
}
|
||||
|
||||
void uwsgi_opt_pythonpath(char *opt, char *value, void *foobar) {
|
||||
|
||||
int i;
|
||||
@@ -232,6 +238,8 @@ pep405:
|
||||
up.wsgi_spitout = PyCFunction_New(uwsgi_spit_method, NULL);
|
||||
up.wsgi_writeout = PyCFunction_New(uwsgi_write_method, NULL);
|
||||
|
||||
up.hook_write_string = python_simple_hook_write_string;
|
||||
|
||||
up.main_thread = PyThreadState_Get();
|
||||
|
||||
// by default set a fake GIL (little impact on performance)
|
||||
|
||||
@@ -186,6 +186,8 @@ struct uwsgi_python {
|
||||
char *pyrun;
|
||||
int start_response_nodelay;
|
||||
|
||||
void (*hook_write_string)(struct wsgi_request *, PyObject *);
|
||||
|
||||
char *programname;
|
||||
};
|
||||
|
||||
|
||||
@@ -163,16 +163,13 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
|
||||
|
||||
// return or yield ?
|
||||
if (PyString_Check((PyObject *)wsgi_req->async_result)) {
|
||||
char *content = PyString_AsString(wsgi_req->async_result);
|
||||
size_t content_len = PyString_Size(wsgi_req->async_result);
|
||||
size_t content_len = PyString_Size((PyObject *)wsgi_req->async_result);
|
||||
if (content_len > 0 && !wsgi_req->headers_sent) {
|
||||
if (uwsgi_python_do_send_headers(wsgi_req)) {
|
||||
goto clear;
|
||||
}
|
||||
}
|
||||
UWSGI_RELEASE_GIL
|
||||
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
|
||||
UWSGI_GET_GIL
|
||||
up.hook_write_string(wsgi_req, (PyObject *) wsgi_req->async_result);
|
||||
uwsgi_py_check_write_errors {
|
||||
uwsgi_py_write_exception(wsgi_req);
|
||||
}
|
||||
@@ -241,16 +238,13 @@ exception:
|
||||
|
||||
|
||||
if (PyString_Check(pychunk)) {
|
||||
char *content = PyString_AsString(pychunk);
|
||||
size_t content_len = PyString_Size(pychunk);
|
||||
if (content_len > 0 && !wsgi_req->headers_sent) {
|
||||
if (uwsgi_python_do_send_headers(wsgi_req)) {
|
||||
goto clear;
|
||||
}
|
||||
}
|
||||
UWSGI_RELEASE_GIL
|
||||
wsgi_req->response_size += wsgi_req->socket->proto_write(wsgi_req, content, content_len);
|
||||
UWSGI_GET_GIL
|
||||
up.hook_write_string(wsgi_req, pychunk);
|
||||
uwsgi_py_check_write_errors {
|
||||
uwsgi_py_write_exception(wsgi_req);
|
||||
Py_DECREF(pychunk);
|
||||
|
||||
Reference in New Issue
Block a user