proposed WSGI2.0 response support

This commit is contained in:
roberto@sirius
2010-06-08 17:44:43 +02:00
parent 52502342e0
commit 8e987ffa18
8 changed files with 89 additions and 1 deletions
+15
View File
@@ -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
+4
View File
@@ -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);
+18 -1
View File
@@ -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();
+14
View File
@@ -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')])
+9
View File
@@ -0,0 +1,9 @@
def mygen(uri):
for i in xrange(1,100):
yield "ciao %s<br/>" % uri
def application(env, start_response = None):
return '200 OK', [('Content-Type', 'text/html')], "<h1>This is the fastest homepage of the world !!!</h1>"
#return '200 OK', [('Content-Type', 'text/html')], mygen(env['PATH_INFO'])
+5
View File
@@ -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);
+10
View File
@@ -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 <stdio.h>
#include <stdlib.h>
@@ -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
+14
View File
@@ -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")