From 8e987ffa181b9b1103616d6ffdf44802d6287831 Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Tue, 8 Jun 2010 17:44:43 +0200 Subject: [PATCH] proposed WSGI2.0 response support --- evdis.c | 15 +++++++++++++++ protocol.c | 4 ++++ pyutils.c | 19 ++++++++++++++++++- simple_app.py | 14 ++++++++++++++ simple_app_wsgi2.py | 9 +++++++++ uwsgi.c | 5 +++++ uwsgi.h | 10 ++++++++++ uwsgiconfig.py | 14 ++++++++++++++ 8 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 evdis.c create mode 100644 simple_app_wsgi2.py diff --git a/evdis.c b/evdis.c new file mode 100644 index 00000000..911b3147 --- /dev/null +++ b/evdis.c @@ -0,0 +1,15 @@ +#ifdef UWSGI_EVDIS + +#include "uwsgi.h" + +void evdis_loop(struct uwsgi_server *uwsgi) { + + // populate event list + +} + + + +#else +#warning "*** Event Dispatcher support is disabled ***" +#endif diff --git a/protocol.c b/protocol.c index 658adeca..d03cb550 100644 --- a/protocol.c +++ b/protocol.c @@ -266,6 +266,10 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header uh->pktsize = uwsgi_swap16(uh->pktsize); #endif +#ifdef UWSGI_DEBUG + uwsgi_debug("uwsgi payload size: %d (%X) modifier1: %d modifier2: %d\n", uh->pktsize, uh->pktsize, uh->modifier1, uh->modifier2); +#endif + /* check for max buffer size */ if (uh->pktsize > uwsgi.buffer_size) { uwsgi_log( "invalid request block size: %d...skip\n", uh->pktsize); diff --git a/pyutils.c b/pyutils.c index c7f91f10..1f2b7bd8 100644 --- a/pyutils.c +++ b/pyutils.c @@ -45,6 +45,21 @@ int manage_python_response(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi } #endif +#ifdef UWSGI_WSGI2 + // is it a tuple (WSGI2.0) ? + if (PyTuple_Check((PyObject *)wsgi_req->async_result)) { + if (PyTuple_Size((PyObject *)wsgi_req->async_result) != 3) { + uwsgi_log("invalid WSGI2.0 response.\n"); + goto clear; + } + if (py_uwsgi_spit(NULL, (PyObject *)wsgi_req->async_result) == Py_None) { + goto clear; + } + wsgi_req->async_orig_result = wsgi_req->async_result ; + wsgi_req->async_result = PyTuple_GetItem((PyObject *)wsgi_req->async_result, 2); + return UWSGI_AGAIN; + } +#endif // ok its a yield if (!wsgi_req->async_placeholder) { @@ -61,7 +76,6 @@ int manage_python_response(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi - pychunk = PyIter_Next(wsgi_req->async_placeholder) ; if (!pychunk) { @@ -108,6 +122,9 @@ clear: } } Py_XDECREF((PyObject *)wsgi_req->async_placeholder); +#ifdef UWSGI_WSGI2 + Py_XDECREF((PyObject *)wsgi_req->async_orig_result); +#endif clear2: Py_DECREF((PyObject *)wsgi_req->async_result); PyErr_Clear(); diff --git a/simple_app.py b/simple_app.py index 7d7c720e..ca4cd095 100644 --- a/simple_app.py +++ b/simple_app.py @@ -1,3 +1,17 @@ +import uwsgi + +print "uWSGI version:", uwsgi.version + +def ciao(): + print "modifica su /tmp" + +def ciao2(): + print "nuovo uwsgi_server" + +#uwsgi.event_add(uwsgi.EVENT_FILE, "/tmp", ciao) +#uwsgi.event_add(uwsgi.EVENT_DNSSD, "_uwsgi._tcp", ciao2) +#uwsgi.event_add(uwsgi.EVENT_TIMER, 1000, ciao2) + def application(env, start_response): print env start_response('200 Ok', [('Content-type', 'text/plain')]) diff --git a/simple_app_wsgi2.py b/simple_app_wsgi2.py new file mode 100644 index 00000000..41907dd9 --- /dev/null +++ b/simple_app_wsgi2.py @@ -0,0 +1,9 @@ + +def mygen(uri): + for i in xrange(1,100): + yield "ciao %s
" % uri + + +def application(env, start_response = None): + return '200 OK', [('Content-Type', 'text/html')], "

This is the fastest homepage of the world !!!

" + #return '200 OK', [('Content-Type', 'text/html')], mygen(env['PATH_INFO']) diff --git a/uwsgi.c b/uwsgi.c index f20e4813..f9624f4c 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -2336,6 +2336,11 @@ void init_uwsgi_embedded_module() { exit(1); } + if (PyDict_SetItemString(uwsgi.embedded_dict, "version", PyString_FromString(UWSGI_VERSION))) { + PyErr_Print(); + exit(1); + } + if (PyDict_SetItemString(uwsgi.embedded_dict, "SPOOL_RETRY", PyInt_FromLong(17))) { PyErr_Print(); exit(1); diff --git a/uwsgi.h b/uwsgi.h index 16e70613..0db91f87 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -5,6 +5,7 @@ #define UWSGI_VERSION "0.9.6-dev" #define uwsgi_error(x) uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__); +#define uwsgi_debug(x, ...) uwsgi_log("[uWSGI DEBUG] " x, __VA_ARGS__); #include #include @@ -346,6 +347,9 @@ struct wsgi_request { void *async_app; void *async_result; +#ifdef UWSGI_WSGI2 + void *async_orig_result; +#endif void *async_placeholder; void *async_args; void *async_environ; @@ -861,3 +865,9 @@ void env_to_arg(char *, char *); void parse_sys_envs(char **, struct option *); void uwsgi_log(const char *, ...); + + +#ifdef UWSGI_EVDIS +#define EVDIS_TYPE_FILE +#define EVDIS_TYPE_DNSSD +#endif diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 245428cd..d7521be7 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -17,10 +17,13 @@ PASTE=True MINTERPRETERS=True ASYNC=True UGREEN=True +EVDIS=True +WSGI2=True STACKLESS=False PLUGINS = [] USWALLOW=False UNBIT=False +DEBUG=True UWSGI_BIN_NAME = 'uwsgi' # specific compilation flags @@ -203,6 +206,11 @@ def parse_vars(): cflags.append("-DUWSGI_PROXY") gcc_list.append('proxy') + if EVDIS: + cflags.append("-DUWSGI_EVDIS") + gcc_list.append('evdis') + + if UGREEN: if uwsgi_os == 'Darwin': cflags.append("-D_XOPEN_SOURCE") @@ -267,6 +275,12 @@ def parse_vars(): cflags.append("-DUWSGI_SPOOLER") gcc_list.append('spooler') + if WSGI2: + cflags.append("-DUWSGI_WSGI2") + + if DEBUG: + cflags.append("-DUWSGI_DEBUG") + if UNBIT: cflags.append("-DUWSGI_UNBIT")