Compare commits

...
32 Commits
Author SHA1 Message Date
roberto@debian32 25d671e0f6 fixed python snmp api 2011-08-26 08:13:14 +02:00
roberto@debian32 5a58281a3f various gevent fixes 2011-08-26 07:37:26 +02:00
roberto@debian32 c422231806 ops another grunt fix 2011-08-25 18:16:58 +02:00
roberto@debian32 4979883fe5 fixed a grunt bug 2011-08-25 17:51:04 +02:00
roberto@debian32 8158a624d3 check for loop engine 2011-08-25 14:34:18 +02:00
roberto@debian32 06403b5fce fixed stupid bug in setup.py 2011-08-25 14:15:55 +02:00
roberto@debian32 bc482652fc updated setup.py 2011-08-25 14:13:13 +02:00
roberto@debian32 58aa5755e0 fixed a typo 2011-08-25 14:04:57 +02:00
roberto@debian32 bca835c58a added UWSGI_PROFILE unix env 2011-08-25 14:03:43 +02:00
roberto@debian32 4b0f68a57a check gevent version 2011-08-25 13:53:38 +02:00
roberto@debian32 b693d73ebe gevent dedicated plugin 2011-08-25 13:46:42 +02:00
roberto@dexter dfab80447b added a check for Riccardo 2011-08-24 18:24:45 +02:00
roberto@dexter bbde0c866a a couple of fixes, and reintroduction of string-based multiapp 2011-08-24 17:48:27 +02:00
roberto@mrspurr 7b3514f757 --emperor-throttle 2011-08-24 13:03:25 +02:00
roberto@mrspurr 6d5fb3b252 export cache and queue functions only if available 2011-08-20 11:12:32 +02:00
roberto@debian32 87e8f118d3 fix refcnt in async-disabled compilation 2011-08-19 16:35:16 +02:00
roberto@debian32 3ae78cc0a8 another bufsize fix 2011-08-19 16:28:44 +02:00
roberto@debian32 7ef921356f updated sharedarea 2011-08-19 15:22:20 +02:00
roberto@debian32 378185d997 added a build profile for uwsgi_pypy integration 2011-08-19 12:24:38 +02:00
roberto@debian32 c4b15a8509 changed final banner in library mode 2011-08-19 12:15:18 +02:00
roberto@debian32 96ef9d155b uwsgi.magic_table 2011-08-19 11:44:40 +02:00
roberto@debian32 d5e6412b20 uWSGI 0.9.9-rc1 2011-08-19 09:57:58 +02:00
roberto@debian32 eebe757c16 Added tag 0.9.9-rc1 for changeset fb168b0b8616 2011-08-19 08:51:26 +02:00
roberto@debian32 43a21d32cb fixed a stupid bug 2011-08-19 08:49:39 +02:00
roberto@debian32 9f9eb5ef17 improved apache2 SCRIPT_NAME/PATH_INFo handling 2011-08-19 08:48:15 +02:00
roberto@debian32 0116c62980 another refcnt fix 2011-08-19 07:06:29 +02:00
roberto@debian32 fae446e495 fix for 3.0-arch 2011-08-19 06:46:07 +02:00
roberto@debian32 6f7054df18 more tolerant cache and queue size 2011-08-18 14:27:21 +02:00
roberto@debian32 0f31c21f4a completed queue subsystem with test 2011-08-18 09:46:32 +02:00
roberto@debian32 bd3e234703 another xml app tag fix 2011-08-18 07:06:27 +02:00
roberto@gambit 71bfd63623 fixed xml app tag 2011-08-18 07:01:13 +02:00
unbit@localhost 98b89dc83c Added tag 0.9.9-beta1 for changeset 6945ee03c7ea 2011-08-18 06:33:20 +02:00
39 changed files with 1018 additions and 300 deletions
+2
View File
@@ -28,3 +28,5 @@ e91bc724325e14c13b8f548c0b6a315c48a1c32a 0.9.8-rc2
fd8477b6348faf16588106055ca59df1c488f76a 0.9.8.1
7169ef1d68d3dab4737bcc3f9e082839e5a06cc1 0.9.8.2
f4d3c4dcd7a63e21fcc9d8d567374c69935178bd 0.9.8.3
6945ee03c7ea95eb19217ef1e1fb17d9ae26adbc 0.9.9-beta1
fb168b0b86169219aa9b8e40f0caa6297cf34dbc 0.9.9-rc1
+12 -23
View File
@@ -161,6 +161,7 @@ static void *uwsgi_server_config(apr_pool_t *p, server_rec *s) {
c->modifier2 = 0 ;
c->cgi_mode = 0 ;
c->max_vars = 128;
c->script_name[0] = 0;
return c;
}
@@ -176,6 +177,12 @@ static void *uwsgi_dir_config(apr_pool_t *p, char *dir) {
c->modifier2 = 0 ;
c->cgi_mode = 0 ;
c->max_vars = 128;
c->script_name[0] = 0;
if (dir) {
if (strcmp(dir, "/")) {
strncpy(c->script_name, dir, 255);
}
}
return c;
}
@@ -347,31 +354,13 @@ static int uwsgi_handler(request_rec *r) {
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "UWSGI_SCHEME", c->scheme, &pkt_size) ;
}
if (c->script_name[0] == '/') {
if (c->script_name[1] == 0) {
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "SCRIPT_NAME", "", &pkt_size) ;
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "PATH_INFO", r->uri, &pkt_size) ;
}
else {
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "SCRIPT_NAME", c->script_name, &pkt_size) ;
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "PATH_INFO", r->uri+strlen(c->script_name), &pkt_size) ;
}
if (c->script_name[0] != 0) {
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "SCRIPT_NAME", c->script_name, &pkt_size) ;
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "PATH_INFO", r->uri+strlen(c->script_name), &pkt_size) ;
}
else {
if (r->path_info) {
if (strlen(r->path_info) <= 0) {
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "SCRIPT_NAME", "", &pkt_size) ;
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "PATH_INFO", r->uri, &pkt_size) ;
}
else {
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "SCRIPT_NAME", apr_pstrndup(r->pool, r->uri, (strlen(r->uri) - strlen(r->path_info) )) , &pkt_size) ;
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "PATH_INFO", r->path_info, &pkt_size) ;
}
}
else {
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "SCRIPT_NAME", "", &pkt_size) ;
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "PATH_INFO", r->uri, &pkt_size) ;
}
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "SCRIPT_NAME", "", &pkt_size) ;
vecptr = uwsgi_add_var(uwsgi_vars, vecptr, r, "PATH_INFO", r->uri, &pkt_size) ;
}
+3
View File
@@ -0,0 +1,3 @@
[uwsgi]
inherit = default
embedded_plugins = python, ping, cache, nagios, rpc, fastrouter, http, gevent
+1 -1
View File
@@ -1,5 +1,5 @@
[uwsgi]
inherit = default
bin_name = libuwsgi.so
embedded_plugins = symcall
embedded_plugins = null
as_shared_library = true
+5
View File
@@ -0,0 +1,5 @@
[uwsgi]
inherit = default
bin_name = libuwsgi.so
embedded_plugins = symcall
as_shared_library = true
+1 -1
View File
@@ -8,7 +8,7 @@ void uwsgi_init_cache() {
if (!uwsgi.cache_blocksize)
uwsgi.cache_blocksize = UMAX16;
if (uwsgi.cache_blocksize % uwsgi.page_size != 0) {
if ((uwsgi.cache_blocksize * uwsgi.cache_max_items) % uwsgi.page_size != 0) {
uwsgi_log("invalid cache blocksize %llu: must be a multiple of memory page size (%d bytes)\n", (unsigned long long) uwsgi.cache_blocksize, uwsgi.page_size);
exit(1);
}
+1 -1
View File
@@ -181,7 +181,7 @@ void emperor_add(char *name, time_t born, char *config, uint32_t config_size) {
char *colon = NULL;
int i;
sleep(1);
usleep(uwsgi.emperor_throttle*1000);
while (c_ui->ui_next) {
c_ui = c_ui->ui_next;
+2 -2
View File
@@ -476,7 +476,7 @@ void master_loop(char **argv, char **environ) {
}
if (uwsgi.queue_store && uwsgi.queue_filesize) {
if (msync(uwsgi.queue, uwsgi.queue_filesize, MS_ASYNC)) {
if (msync(uwsgi.queue_header, uwsgi.queue_filesize, MS_ASYNC)) {
uwsgi_error("msync()");
}
}
@@ -1194,7 +1194,7 @@ void master_loop(char **argv, char **environ) {
}
if (uwsgi.queue_store && uwsgi.queue_filesize && uwsgi.queue_store_sync && ((uwsgi.master_cycles % uwsgi.queue_store_sync) == 0)) {
if (msync(uwsgi.queue, uwsgi.queue_filesize, MS_ASYNC)) {
if (msync(uwsgi.queue_header, uwsgi.queue_filesize, MS_ASYNC)) {
uwsgi_error("msync()");
}
}
+240
View File
@@ -0,0 +1,240 @@
#include "../python/uwsgi_python.h"
extern struct uwsgi_server uwsgi;
extern struct uwsgi_python up;
struct option gevent_options[] = {
{ 0, 0, 0, 0 }
};
#define GEVENT_SWITCH PyObject *gswitch = python_call(ugevent.greenlet_switch, ugevent.greenlet_switch_args, 0, NULL); Py_DECREF(gswitch)
#define GET_CURRENT_GREENLET python_call(ugevent.get_current, ugevent.get_current_args, 0, NULL)
#define free_req_queue uwsgi.async_queue_unused_ptr++; uwsgi.async_queue_unused[uwsgi.async_queue_unused_ptr] = uwsgi.wsgi_req
struct uwsgi_gevent {
PyObject *greenlet_switch;
PyObject *greenlet_switch_args;
PyObject *get_current;
PyObject *get_current_args;
PyObject *hub_loop;
PyObject *spawn;
PyObject *greenlet_args;
} ugevent;
PyObject* gevent_wait_io_and_switch(int fd, PyObject *greenlet_switch) {
PyObject *watcher = PyObject_CallMethod(ugevent.hub_loop, "io", "ii", fd, 1);
if (!watcher) {
PyErr_Print();
return NULL;
}
PyObject *ret = PyObject_CallMethod(watcher, "start", "O", greenlet_switch);
Py_DECREF(ret);
return watcher;
}
PyObject *py_uwsgi_gevent_callback(PyObject * self, PyObject * args) {
struct wsgi_request *wsgi_req = find_first_available_wsgi_req();
if (wsgi_req == NULL) {
uwsgi_log("async queue is full !!!\n");
goto clear;
}
uwsgi.wsgi_req = wsgi_req;
wsgi_req_setup(wsgi_req, wsgi_req->async_id, uwsgi.sockets );
uwsgi.core[wsgi_req->async_id]->in_request = 1;
gettimeofday(&wsgi_req->start_of_request, NULL);
if (wsgi_req_simple_accept(wsgi_req, uwsgi.sockets->fd)) {
uwsgi_close_request(wsgi_req);
free_req_queue;
goto clear;
}
PyTuple_SetItem(ugevent.greenlet_args, 1, PyLong_FromLong((long)wsgi_req));
PyObject *new_gl = python_call(ugevent.spawn, ugevent.greenlet_args, 0, NULL);
Py_DECREF(new_gl);
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_uwsgi_gevent_greenlet(PyObject * self, PyObject * args) {
PyObject *py_wsgi_req = PyTuple_GetItem(args, 0);
struct wsgi_request *wsgi_req = (struct wsgi_request *) PyLong_AsLong(py_wsgi_req);
int status ;
PyObject *current_greenlet = GET_CURRENT_GREENLET;
PyObject *greenlet_switch = PyObject_GetAttrString(current_greenlet, "switch");
for(;;) {
uwsgi.wsgi_req = wsgi_req;
PyObject *watcher = gevent_wait_io_and_switch(wsgi_req->poll.fd, greenlet_switch);
if (!watcher) {
goto clear;
}
uwsgi.wsgi_req = wsgi_req;
status = wsgi_req->socket->proto(wsgi_req);
PyObject *ret = PyObject_CallMethod(watcher, "stop", NULL);
Py_DECREF(ret);
Py_DECREF(watcher);
if (status < 0) {
goto clear;
}
else if (status == 0) {
break;
}
}
for(;;) {
uwsgi.wsgi_req = wsgi_req;
wsgi_req->async_status = uwsgi.p[wsgi_req->uh.modifier1]->request(wsgi_req);
if (wsgi_req->async_status <= UWSGI_OK) {
goto clear;
}
GEVENT_SWITCH;
}
clear:
Py_DECREF(greenlet_switch);
Py_DECREF(current_greenlet);
uwsgi_close_request(wsgi_req);
uwsgi.wsgi_req = wsgi_req;
free_req_queue;
Py_INCREF(Py_None);
return Py_None;
}
PyMethodDef uwsgi_gevent_callback_method[] = { {"uwsgi_gevent_callback", py_uwsgi_gevent_callback, METH_VARARGS, ""} };
PyMethodDef uwsgi_gevent_greenlet_method[] = { {"uwsgi_gevent_greenlet", py_uwsgi_gevent_greenlet, METH_VARARGS, ""} };
void gevent_loop() {
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
if (uwsgi.async < 2) {
uwsgi_log("the gevent loop engine requires async mode (--async <n>)\n");
exit(1);
}
PyObject *gevent_dict = get_uwsgi_pydict("gevent");
if (!gevent_dict) {
PyErr_Print();
exit(1);
}
PyObject *gevent_version = PyDict_GetItemString(gevent_dict, "version_info");
if (!gevent_version) {
PyErr_Print();
exit(1);
}
if (PyInt_AsLong(PyTuple_GetItem(gevent_version, 0)) < 1) {
uwsgi_log("uWSGI requires at least gevent 1.x version\n");
exit(1);
}
ugevent.spawn = PyDict_GetItemString(gevent_dict, "spawn");
if (!ugevent.spawn) {
PyErr_Print();
exit(1);
}
ugevent.greenlet_switch = PyDict_GetItemString(gevent_dict, "sleep");
if (!ugevent.greenlet_switch) {
PyErr_Print();
exit(1);
}
ugevent.greenlet_switch_args = PyTuple_New(0);
Py_INCREF(ugevent.greenlet_switch_args);
PyObject *gevent_get_hub = PyDict_GetItemString(gevent_dict, "get_hub");
PyObject *gevent_hub = python_call(gevent_get_hub, PyTuple_New(0), 0, NULL);
if (!gevent_hub) {
PyErr_Print();
exit(1);
}
ugevent.get_current = PyDict_GetItemString(gevent_dict, "getcurrent");
if (!ugevent.get_current) {
PyErr_Print();
exit(1);
}
ugevent.get_current_args = PyTuple_New(0);
Py_INCREF(ugevent.get_current_args);
ugevent.hub_loop = PyObject_GetAttrString(gevent_hub, "loop");
if (!ugevent.hub_loop) {
PyErr_Print();
exit(1);
}
PyObject *watcher = PyObject_CallMethod(ugevent.hub_loop, "io", "ii", uwsgi_sock->fd, 1);
if (!watcher) {
PyErr_Print();
exit(1);
}
PyObject *uwsgi_gevent_callback = PyCFunction_New(uwsgi_gevent_callback_method, NULL);
Py_INCREF(uwsgi_gevent_callback);
PyObject *uwsgi_gevent_greenlet = PyCFunction_New(uwsgi_gevent_greenlet_method, NULL);
Py_INCREF(uwsgi_gevent_greenlet);
ugevent.greenlet_args = PyTuple_New(2);
PyTuple_SetItem(ugevent.greenlet_args, 0, uwsgi_gevent_greenlet);
PyObject_CallMethod(watcher, "start", "O", uwsgi_gevent_callback);
if (PyObject_CallMethod(gevent_hub, "switch", NULL)) {
PyErr_Print();
exit(1);
}
uwsgi_log("the gevent Hub is no more :(\n");
}
int gevent_init() {
uwsgi_register_loop( (char *) "gevent", gevent_loop);
return 0;
}
struct uwsgi_plugin gevent_plugin = {
.name = "gevent",
.init = gevent_init,
.options = gevent_options,
};
+8
View File
@@ -0,0 +1,8 @@
from distutils import sysconfig
NAME='gevent'
CFLAGS = ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True)]
LDFLAGS = []
LIBS = []
GCC_LIST = ['gevent']
+24 -2
View File
@@ -170,8 +170,16 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
wi->mountpoint_len = strlen(wi->mountpoint);
wsgi_req->appid = wi->mountpoint;
wsgi_req->appid_len = wi->mountpoint_len;
#ifdef UWSGI_DEBUG
uwsgi_log("main mountpoint = %s\n", wi->mountpoint);
#endif
wi->callable = PyDict_GetItem(applications, app_mnt);
if (PyString_Check((PyObject *) wi->callable)) {
PyObject *callables_dict = get_uwsgi_pydict((char *)arg1);
if (callables_dict) {
wi->callable = PyDict_GetItem(callables_dict, (PyObject *)wi->callable);
}
}
}
Py_INCREF((PyObject *)wi->callable);
@@ -248,6 +256,8 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
}
#else
// add start_response on WSGI app
Py_INCREF((PyObject *)up.wsgi_spitout);
wi->wsgi_args = PyTuple_New(wi->argc);
if (app_type == PYTHON_APP_TYPE_WSGI) {
if (PyTuple_SetItem(wi->wsgi_args, 1, up.wsgi_spitout)) {
@@ -308,7 +318,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
uwsgi_log( "Pump application %d (mountpoint=%.*s) ready on interpreter %p pid: %d", id, wi->mountpoint_len, wi->mountpoint, wi->interpreter, (int) getpid());
}
if (!wsgi_req->appid_len) {
if ((wsgi_req->appid_len == 0 || (wsgi_req->appid_len = 1 && wsgi_req->appid[0] == '/')) && uwsgi.default_app == -1) {
uwsgi_rawlog(" (default app)");
uwsgi.default_app = id;
}
@@ -327,7 +337,19 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
wsgi_req->appid = PyString_AsString(app_mnt);
wsgi_req->appid_len = strlen(wsgi_req->appid);
init_uwsgi_app(LOADER_CALLABLE, PyDict_GetItem(applications, app_mnt), wsgi_req, wi->interpreter, app_type);
PyObject *a_callable = PyDict_GetItem(applications, app_mnt);
if (PyString_Check(a_callable)) {
PyObject *callables_dict = get_uwsgi_pydict((char *)arg1);
if (callables_dict) {
a_callable = PyDict_GetItem(callables_dict, a_callable);
}
}
if (!a_callable) {
uwsgi_log("skipping broken app %s\n", wsgi_req->appid);
continue;
}
init_uwsgi_app(LOADER_CALLABLE, a_callable, wsgi_req, wi->interpreter, app_type);
}
}
+29 -2
View File
@@ -456,6 +456,8 @@ void init_uwsgi_embedded_module() {
exit(1);
}
Py_INCREF((PyObject *) &uwsgi_InputType);
up.embedded_dict = PyModule_GetDict(new_uwsgi_module);
if (!up.embedded_dict) {
uwsgi_log("could not get uwsgi module __dict__\n");
@@ -576,6 +578,23 @@ void init_uwsgi_embedded_module() {
exit(1);
}
PyObject *py_magic_table = PyDict_New();
uint8_t mtk;
for (i = 0; i <= 0xff; i++) {
// a bit of magic :P
mtk = i;
if (uwsgi.magic_table[i]) {
if (uwsgi.magic_table[i][0] != 0) {
PyDict_SetItem(py_magic_table, PyString_FromStringAndSize((char *) &mtk, 1), PyString_FromString(uwsgi.magic_table[i]));
}
}
}
if (PyDict_SetItemString(up.embedded_dict, "magic_table", py_magic_table)) {
PyErr_Print();
exit(1);
}
#ifdef UNBIT
if (PyDict_SetItemString(up.embedded_dict, "unbit", Py_True)) {
#else
@@ -654,9 +673,17 @@ void init_uwsgi_embedded_module() {
init_uwsgi_module_sharedarea(new_uwsgi_module);
}
init_uwsgi_module_cache(new_uwsgi_module);
if (uwsgi.cache_max_items > 0) {
init_uwsgi_module_cache(new_uwsgi_module);
}
init_uwsgi_module_queue(new_uwsgi_module);
if (uwsgi.queue_size > 0) {
init_uwsgi_module_queue(new_uwsgi_module);
}
if (uwsgi.snmp) {
init_uwsgi_module_snmp(new_uwsgi_module);
}
if (up.extension) {
up.extension();
+9 -4
View File
@@ -351,13 +351,15 @@ clear:
}
static PyMethodDef symimporter_methods[] = {
{"find_module", symimporter_find_module, METH_VARARGS},
{"load_module", symimporter_load_module, METH_VARARGS},
{"find_module", symimporter_find_module, METH_VARARGS},
{"load_module", symimporter_load_module, METH_VARARGS},
{ NULL, NULL },
};
static PyMethodDef symzipimporter_methods[] = {
{"find_module", symzipimporter_find_module, METH_VARARGS},
{"load_module", symzipimporter_load_module, METH_VARARGS},
{"find_module", symzipimporter_find_module, METH_VARARGS},
{"load_module", symzipimporter_load_module, METH_VARARGS},
{ NULL, NULL },
};
static void uwsgi_symimporter_free(struct _symimporter *self) {
@@ -717,6 +719,7 @@ int uwsgi_init_symbol_import() {
exit(1);
}
Py_INCREF((PyObject *)&SymImporter_Type);
if (PyModule_AddObject(uwsgi_em, "SymbolsImporter",
(PyObject *)&SymImporter_Type) < 0) {
PyErr_Print();
@@ -724,6 +727,7 @@ int uwsgi_init_symbol_import() {
exit(1);
}
Py_INCREF((PyObject *)&ZipImporter_Type);
if (PyModule_AddObject(uwsgi_em, "ZipImporter",
(PyObject *)&ZipImporter_Type) < 0) {
PyErr_Print();
@@ -731,6 +735,7 @@ int uwsgi_init_symbol_import() {
exit(1);
}
Py_INCREF((PyObject *)&SymZipImporter_Type);
if (PyModule_AddObject(uwsgi_em, "SymbolsZipImporter",
(PyObject *)&SymZipImporter_Type) < 0) {
PyErr_Print();
+294 -47
View File
@@ -838,17 +838,29 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) {
return NULL;
}
if (PyString_Check(what)) {
filename = PyString_AsString(what);
fd = open(filename, O_RDONLY);
if (fd < 0) {
uwsgi_error("open");
uwsgi_error_open(filename);
goto clear;
}
}
#ifdef PYTHREE
else if (PyUnicode_Check(what)) {
filename = PyBytes_AsString(PyUnicode_AsASCIIString(what));
fd = open(filename, O_RDONLY);
if (fd < 0) {
uwsgi_error_open(filename);
goto clear;
}
}
#endif
else {
fd = PyObject_AsFileDescriptor(what);
if (fd < 0)
@@ -1007,81 +1019,102 @@ PyObject *py_uwsgi_embedded_data(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_sharedarea_inclong(PyObject * self, PyObject * args) {
int pos = 0;
long value = 0;
uint64_t pos = 0;
uint64_t value = 1;
uint64_t current_value = 0;
if (uwsgi.sharedareasize <= 0) {
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "ii:sharedarea_inclong", &pos, &value)) {
if (!PyArg_ParseTuple(args, "l|l:sharedarea_inclong", &pos, &value)) {
return NULL;
}
if (pos + 4 >= uwsgi.page_size * uwsgi.sharedareasize) {
if (pos + 8 >= uwsgi.page_size * uwsgi.sharedareasize) {
Py_INCREF(Py_None);
return Py_None;
}
memcpy(&value, uwsgi.sharedarea + pos, 4);
value++;
memcpy(uwsgi.sharedarea + pos, &value, 4);
uwsgi_wlock(uwsgi.sa_lock);
return PyInt_FromLong(value);
memcpy(&current_value, uwsgi.sharedarea + pos, 8);
value = current_value + value;
memcpy(uwsgi.sharedarea + pos, &value, 8);
PyObject *ret = PyInt_FromLong(value);
uwsgi_rwunlock(uwsgi.sa_lock);
return ret;
}
PyObject *py_uwsgi_sharedarea_writelong(PyObject * self, PyObject * args) {
int pos = 0;
long value;
uint64_t pos = 0;
uint64_t value = 0;
if (uwsgi.sharedareasize <= 0) {
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "ii:sharedarea_writelong", &pos, &value)) {
if (!PyArg_ParseTuple(args, "ll:sharedarea_writelong", &pos, &value)) {
return NULL;
}
if (pos + 4 >= uwsgi.page_size * uwsgi.sharedareasize) {
if (pos + 8 >= uwsgi.page_size * uwsgi.sharedareasize) {
Py_INCREF(Py_None);
return Py_None;
}
memcpy(uwsgi.sharedarea + pos, &value, 4);
uwsgi_wlock(uwsgi.sa_lock);
return PyInt_FromLong(value);
memcpy(uwsgi.sharedarea + pos, &value, 8);
PyObject *ret = PyInt_FromLong(value);
uwsgi_rwunlock(uwsgi.sa_lock);
return ret;
}
PyObject *py_uwsgi_sharedarea_write(PyObject * self, PyObject * args) {
int pos = 0;
uint64_t pos = 0;
char *value;
Py_ssize_t value_len = 0;
if (uwsgi.sharedareasize <= 0) {
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "is:sharedarea_write", &pos, &value)) {
if (!PyArg_ParseTuple(args, "ls#:sharedarea_write", &pos, &value, &value_len)) {
return NULL;
}
if (pos + (int) strlen(value) >= uwsgi.page_size * uwsgi.sharedareasize) {
if (pos + value_len >= uwsgi.page_size * uwsgi.sharedareasize) {
Py_INCREF(Py_None);
return Py_None;
}
memcpy(uwsgi.sharedarea + pos, value, strlen(value));
uwsgi_wlock(uwsgi.sa_lock);
return PyInt_FromLong(strlen(value));
memcpy(uwsgi.sharedarea + pos, value, value_len);
PyObject *ret = PyInt_FromLong(value_len);
uwsgi_rwunlock(uwsgi.sa_lock);
return ret;
}
PyObject *py_uwsgi_sharedarea_writebyte(PyObject * self, PyObject * args) {
int pos = 0;
uint64_t pos = 0;
char value;
if (uwsgi.sharedareasize <= 0) {
@@ -1090,7 +1123,7 @@ PyObject *py_uwsgi_sharedarea_writebyte(PyObject * self, PyObject * args) {
}
if (!PyArg_ParseTuple(args, "ib:sharedarea_writebyte", &pos, &value)) {
if (!PyArg_ParseTuple(args, "lb:sharedarea_writebyte", &pos, &value)) {
return NULL;
}
@@ -1099,46 +1132,58 @@ PyObject *py_uwsgi_sharedarea_writebyte(PyObject * self, PyObject * args) {
return Py_None;
}
uwsgi_wlock(uwsgi.sa_lock);
uwsgi.sharedarea[pos] = value;
return PyInt_FromLong(uwsgi.sharedarea[pos]);
PyObject *ret = PyInt_FromLong(uwsgi.sharedarea[pos]);
uwsgi_rwunlock(uwsgi.sa_lock);
return ret;
}
PyObject *py_uwsgi_sharedarea_readlong(PyObject * self, PyObject * args) {
int pos = 0;
long value;
uint64_t pos = 0;
uint64_t value;
if (uwsgi.sharedareasize <= 0) {
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "i:sharedarea_readlong", &pos)) {
if (!PyArg_ParseTuple(args, "l:sharedarea_readlong", &pos)) {
return NULL;
}
if (pos + 4 >= uwsgi.page_size * uwsgi.sharedareasize) {
if (pos + 8 >= uwsgi.page_size * uwsgi.sharedareasize) {
Py_INCREF(Py_None);
return Py_None;
}
memcpy(&value, uwsgi.sharedarea + pos, 4);
uwsgi_wlock(uwsgi.sa_lock);
return PyInt_FromLong(value);
memcpy(&value, uwsgi.sharedarea + pos, 8);
PyObject *ret = PyLong_FromLong(value);
uwsgi_rwunlock(uwsgi.sa_lock);
return ret;
}
PyObject *py_uwsgi_sharedarea_readbyte(PyObject * self, PyObject * args) {
int pos = 0;
uint64_t pos = 0;
if (uwsgi.sharedareasize <= 0) {
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "i:sharedarea_readbyte", &pos)) {
if (!PyArg_ParseTuple(args, "l:sharedarea_readbyte", &pos)) {
return NULL;
}
@@ -1147,20 +1192,26 @@ PyObject *py_uwsgi_sharedarea_readbyte(PyObject * self, PyObject * args) {
return Py_None;
}
return PyInt_FromLong(uwsgi.sharedarea[pos]);
uwsgi_wlock(uwsgi.sa_lock);
PyObject *ret = PyInt_FromLong(uwsgi.sharedarea[pos]);
uwsgi_rwunlock(uwsgi.sa_lock);
return ret;
}
PyObject *py_uwsgi_sharedarea_read(PyObject * self, PyObject * args) {
int pos = 0;
int len = 1;
uint64_t pos = 0;
uint64_t len = 1;
if (uwsgi.sharedareasize <= 0) {
Py_INCREF(Py_None);
return Py_None;
}
if (!PyArg_ParseTuple(args, "i|i:sharedarea_read", &pos, &len)) {
if (!PyArg_ParseTuple(args, "l|l:sharedarea_read", &pos, &len)) {
return NULL;
}
@@ -1169,7 +1220,13 @@ PyObject *py_uwsgi_sharedarea_read(PyObject * self, PyObject * args) {
return Py_None;
}
return PyString_FromStringAndSize(uwsgi.sharedarea + pos, len);
uwsgi_wlock(uwsgi.sa_lock);
PyObject *ret = PyString_FromStringAndSize(uwsgi.sharedarea + pos, len);
uwsgi_rwunlock(uwsgi.sa_lock);
return ret;
}
#ifdef UWSGI_SPOOLER
@@ -2276,7 +2333,9 @@ PyObject *py_uwsgi_disconnect(PyObject * self, PyObject * args) {
uwsgi_log("disconnecting worker %d (pid :%d) from session...\n", uwsgi.mywid, uwsgi.mypid);
#endif
fclose(wsgi_req->async_post);
if (wsgi_req->socket) {
wsgi_req->socket->proto_close(wsgi_req);
}
wsgi_req->fd_closed = 1;
Py_INCREF(Py_True);
@@ -2433,7 +2492,9 @@ PyObject *py_uwsgi_grunt(PyObject * self, PyObject * args) {
// close connection on the worker
if (PyTuple_Size(args) == 0) {
fclose(wsgi_req->async_post);
if (wsgi_req->socket) {
wsgi_req->socket->proto_close(wsgi_req);
}
wsgi_req->fd_closed = 1;
}
@@ -2808,25 +2869,58 @@ PyObject *py_uwsgi_queue_push(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_queue_set(PyObject * self, PyObject * args) {
Py_ssize_t msglen = 0;
uint64_t pos = 0;
char *message ;
PyObject *res;
if (!PyArg_ParseTuple(args, "ls#:queue_set", &pos, &message, &msglen)) {
return NULL;
}
if (uwsgi.queue_size) {
uwsgi_wlock(uwsgi.queue_lock);
if (uwsgi_queue_set(pos, message, msglen)) {
Py_INCREF(Py_True);
res = Py_True;
}
else {
Py_INCREF(Py_None);
res = Py_None;
}
uwsgi_rwunlock(uwsgi.queue_lock);
return res;
}
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_uwsgi_queue_slot(PyObject * self, PyObject * args) {
return PyInt_FromLong(uwsgi.shared->queue_pos);
return PyInt_FromLong(uwsgi.queue_header->pos);
}
PyObject *py_uwsgi_queue_pull_slot(PyObject * self, PyObject * args) {
return PyInt_FromLong(uwsgi.queue_header->pull_pos);
}
PyObject *py_uwsgi_queue_pull(PyObject * self, PyObject * args) {
char *message;
uint64_t size;
PyObject *res;
if (!PyArg_ParseTuple(args, ":queue_pull")) {
return NULL;
}
if (uwsgi.queue_size) {
uwsgi_wlock(uwsgi.queue_lock);
message = uwsgi_queue_pull(&size);
if (message) {
if (message && size > 0) {
res = PyString_FromStringAndSize(message, size);
}
else {
@@ -2842,6 +2936,32 @@ PyObject *py_uwsgi_queue_pull(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_queue_pop(PyObject * self, PyObject * args) {
char *message;
uint64_t size;
PyObject *res;
if (uwsgi.queue_size) {
uwsgi_wlock(uwsgi.queue_lock);
message = uwsgi_queue_pop(&size);
if (message && size > 0) {
res = PyString_FromStringAndSize(message, size);
}
else {
Py_INCREF(Py_None);
res = Py_None;
}
uwsgi_rwunlock(uwsgi.queue_lock);
return res;
}
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_uwsgi_queue_get(PyObject * self, PyObject * args) {
long index = 0;
@@ -2856,7 +2976,7 @@ PyObject *py_uwsgi_queue_get(PyObject * self, PyObject * args) {
if (uwsgi.queue_size) {
uwsgi_rlock(uwsgi.queue_lock);
message = uwsgi_queue_get(index, &size);
if (message) {
if (message && size > 0) {
res = PyString_FromStringAndSize(message, size);
}
else {
@@ -2886,8 +3006,8 @@ PyObject *py_uwsgi_queue_last(PyObject * self, PyObject * args) {
if (uwsgi.queue_size) {
res = PyList_New(0);
uwsgi_rlock(uwsgi.queue_lock);
if (uwsgi.shared->queue_pos > 0) {
base = uwsgi.shared->queue_pos-1;
if (uwsgi.queue_header->pos > 0) {
base = uwsgi.queue_header->pos-1;
}
else {
base = uwsgi.queue_size-1;
@@ -2988,10 +3108,13 @@ static PyMethodDef uwsgi_cache_methods[] = {
static PyMethodDef uwsgi_queue_methods[] = {
{"queue_get", py_uwsgi_queue_get, METH_VARARGS, ""},
{"queue_set", py_uwsgi_queue_set, METH_VARARGS, ""},
{"queue_last", py_uwsgi_queue_last, METH_VARARGS, ""},
{"queue_push", py_uwsgi_queue_push, METH_VARARGS, ""},
{"queue_pull", py_uwsgi_queue_pull, METH_VARARGS, ""},
{"queue_pop", py_uwsgi_queue_pop, METH_VARARGS, ""},
{"queue_slot", py_uwsgi_queue_slot, METH_VARARGS, ""},
{"queue_pull_slot", py_uwsgi_queue_pull_slot, METH_VARARGS, ""},
{NULL, NULL},
};
@@ -3072,6 +3195,8 @@ void init_uwsgi_module_queue(PyObject * current_uwsgi_module) {
PyDict_SetItemString(uwsgi_module_dict, uwsgi_function->ml_name, func);
Py_DECREF(func);
}
PyDict_SetItemString(uwsgi_module_dict, "queue_size", PyInt_FromLong(uwsgi.queue_size));
}
@@ -3092,4 +3217,126 @@ void init_uwsgi_module_sharedarea(PyObject * current_uwsgi_module) {
}
}
PyObject *py_snmp_counter32(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bI:snmp_set_counter32", &oid_num, &oid_val)) {
return NULL;
}
if (oid_num > 100 || oid_num < 1)
goto clear;
uwsgi.shared->snmp_value[oid_num - 1].type = SNMP_COUNTER32;
uwsgi.shared->snmp_value[oid_num - 1].val = oid_val;
Py_INCREF(Py_True);
return Py_True;
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_snmp_counter64(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint64_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bK:snmp_set_counter64", &oid_num, &oid_val)) {
return NULL;
}
if (oid_num > 100 || oid_num < 1)
goto clear;
uwsgi.shared->snmp_value[oid_num - 1].type = SNMP_COUNTER64;
uwsgi.shared->snmp_value[oid_num - 1].val = oid_val;
Py_INCREF(Py_True);
return Py_True;
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_snmp_gauge(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bI:snmp_set_gauge", &oid_num, &oid_val)) {
return NULL;
}
if (oid_num > 100 || oid_num < 1)
goto clear;
uwsgi.shared->snmp_value[oid_num - 1].type = SNMP_GAUGE;
uwsgi.shared->snmp_value[oid_num - 1].val = oid_val;
Py_INCREF(Py_True);
return Py_True;
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_snmp_community(PyObject * self, PyObject * args) {
char *snmp_community;
if (!PyArg_ParseTuple(args, "s:snmp_set_community", &snmp_community)) {
return NULL;
}
if (strlen(snmp_community) > 72) {
uwsgi_log( "*** warning the supplied SNMP community string will be truncated to 72 chars ***\n");
memcpy(uwsgi.shared->snmp_community, snmp_community, 72);
}
else {
memcpy(uwsgi.shared->snmp_community, snmp_community, strlen(snmp_community) + 1);
}
Py_INCREF(Py_True);
return Py_True;
}
static PyMethodDef uwsgi_snmp_methods[] = {
{"snmp_set_counter32", py_snmp_counter32, METH_VARARGS, ""},
{"snmp_set_counter64", py_snmp_counter64, METH_VARARGS, ""},
{"snmp_set_gauge", py_snmp_gauge, METH_VARARGS, ""},
{"snmp_set_community", py_snmp_community, METH_VARARGS, ""},
{NULL, NULL},
};
void init_uwsgi_module_snmp(PyObject * current_uwsgi_module) {
PyMethodDef *uwsgi_function;
PyObject *uwsgi_module_dict = PyModule_GetDict(current_uwsgi_module);
if (!uwsgi_module_dict) {
uwsgi_log("could not get uwsgi module __dict__\n");
exit(1);
}
for (uwsgi_function = uwsgi_snmp_methods; uwsgi_function->ml_name != NULL; uwsgi_function++) {
PyObject *func = PyCFunction_New(uwsgi_function, NULL);
PyDict_SetItemString(uwsgi_module_dict, uwsgi_function->ml_name, func);
Py_DECREF(func);
}
uwsgi_log( "SNMP python functions initialized.\n");
}
#endif
+1
View File
@@ -249,6 +249,7 @@ void init_uwsgi_module_spooler(PyObject *);
void init_uwsgi_module_sharedarea(PyObject *);
void init_uwsgi_module_cache(PyObject *);
void init_uwsgi_module_queue(PyObject *);
void init_uwsgi_module_snmp(PyObject *);
PyObject *uwsgi_pyimport_by_filename(char *, char *);
+3 -1
View File
@@ -125,7 +125,9 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_
PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.version", wi->uwsgi_version);
if (uwsgi.cores > 1) {
PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.core", PyInt_FromLong(wsgi_req->async_id));
zero = PyInt_FromLong(wsgi_req->async_id);
PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.core", zero);
Py_DECREF(zero);
}
// cache this ?
+1 -1
View File
@@ -2,7 +2,7 @@ import os,sys
NAME='python24'
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
CFLAGS = os.popen('python2.4-config --cflags').read().rstrip().split()
CFLAGS.append('-Wno-unused-parameter')
+1 -1
View File
@@ -2,7 +2,7 @@ import os,sys
NAME='python25'
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
CFLAGS = os.popen('python2.5-config --cflags').read().rstrip().split()
CFLAGS.append('-Wno-unused-parameter')
+1 -1
View File
@@ -2,7 +2,7 @@ import os,sys
NAME='python26'
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
CFLAGS = os.popen('python2.6-config --cflags').read().rstrip().split()
CFLAGS.append('-Wno-unused-parameter')
+1 -1
View File
@@ -2,7 +2,7 @@ import os,sys
NAME='python27'
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
CFLAGS = os.popen('python2.7-config --cflags').read().rstrip().split()
CFLAGS.append('-Wno-unused-parameter')
+1 -1
View File
@@ -2,7 +2,7 @@ import os,sys
NAME='python30'
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'gil', 'uwsgi_pymodule', 'profiler'])
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
CFLAGS = os.popen('python3.0-config --cflags').read().rstrip().split()
CFLAGS.append('-Wno-unused-parameter')
+1 -1
View File
@@ -2,7 +2,7 @@ import os,sys
NAME='python31'
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'gil', 'uwsgi_pymodule', 'profiler'])
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
CFLAGS = os.popen('python3.1-config --cflags').read().rstrip().split()
CFLAGS.append('-Wno-unused-parameter')
+1 -1
View File
@@ -2,7 +2,7 @@ import os,sys
NAME='python32'
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'gil', 'uwsgi_pymodule', 'profiler'])
GCC_LIST = map(lambda x: '../python/' + x, ['python_plugin', 'pyutils', 'pyloader', 'wsgi_handlers', 'wsgi_headers', 'wsgi_subhandler', 'web3_subhandler', 'pump_subhandler', 'gil', 'uwsgi_pymodule', 'profiler', 'symimporter'])
CFLAGS = os.popen('python3.2-config --cflags').read().rstrip().split()
CFLAGS.append('-Wno-unused-parameter')
+2 -2
View File
@@ -717,7 +717,7 @@ next:
}
// on tiny post use memory
else {
if (!uwsgi_read_whole_body_in_mem(wsgi_req, uwsgi.mem_post_buf[wsgi_req->async_id], uwsgi.post_buffering)) {
if (!uwsgi_read_whole_body_in_mem(wsgi_req, wsgi_req->post_buffering_buf)) {
wsgi_req->status = -1;
return -1;
}
@@ -767,7 +767,7 @@ next:
script_name = wsgi_req->var_cnt;
}
for(i=0;i<uwsgi_apps_cnt;i++) {
//uwsgi_log("app mountpoint = %.*s\n", uwsgi.apps[i].mountpoint_len, uwsgi.apps[i].mountpoint);
//uwsgi_log("app mountpoint = %.*s\n", uwsgi_apps[i].mountpoint_len, uwsgi_apps[i].mountpoint);
if (orig_path_info_len >= uwsgi_apps[i].mountpoint_len) {
if (!uwsgi_startswith(orig_path_info, uwsgi_apps[i].mountpoint, uwsgi_apps[i].mountpoint_len) && uwsgi_apps[i].mountpoint_len > best_found) {
best_found = uwsgi_apps[i].mountpoint_len;
+53 -33
View File
@@ -6,17 +6,15 @@ void uwsgi_init_queue() {
if (!uwsgi.queue_blocksize)
uwsgi.queue_blocksize = 8192;
if (uwsgi.queue_blocksize % uwsgi.page_size != 0) {
uwsgi_log("invalid queue blocksize %llu: must be a multiple of memory page size (%d bytes)\n", (unsigned long long) uwsgi.queue_blocksize, uwsgi.page_size);
if ((uwsgi.queue_blocksize * uwsgi.queue_size) % uwsgi.page_size != 0) {
uwsgi_log("invalid queue size/blocksize %llu: must be a multiple of memory page size (%d bytes)\n", (unsigned long long) uwsgi.queue_blocksize, uwsgi.page_size);
exit(1);
}
uwsgi.shared->queue_pos = 0;
uwsgi.shared->queue_pull_pos = 0;
if (uwsgi.queue_store) {
uwsgi.queue_filesize = uwsgi.queue_blocksize * uwsgi.queue_size;
uwsgi.queue_filesize = uwsgi.queue_blocksize * uwsgi.queue_size + 16;
int queue_fd;
struct stat qst;
@@ -45,16 +43,26 @@ void uwsgi_init_queue() {
exit(1);
}
uwsgi.queue = mmap(NULL, uwsgi.queue_filesize, PROT_READ | PROT_WRITE, MAP_SHARED, queue_fd, 0);
uwsgi_queue_fix();
// fix header
uwsgi.queue_header = uwsgi.queue;
uwsgi.queue+=16;
}
else {
uwsgi.queue = mmap(NULL, uwsgi.queue_blocksize * uwsgi.queue_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
uwsgi.queue = mmap(NULL, (uwsgi.queue_blocksize * uwsgi.queue_size)+16, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
// fix header
uwsgi.queue_header = uwsgi.queue;
uwsgi.queue+=16;
uwsgi.queue_header->pos = 0;
uwsgi.queue_header->pull_pos = 0;
}
if (!uwsgi.queue) {
uwsgi_error("mmap()");
exit(1);
}
uwsgi.queue_lock = uwsgi_mmap_shared_rwlock();
uwsgi_rwlock_init(uwsgi.queue_lock);
@@ -78,33 +86,20 @@ char *uwsgi_queue_get(uint64_t index, uint64_t *size) {
}
void uwsgi_queue_fix() {
uint64_t i;
char *value;
uint64_t size;
for(i=0;i< uwsgi.queue_size;i++) {
// valid record ?
value = uwsgi_queue_get(i, &size);
if (value && size) {
uwsgi.shared->queue_pos++;
}
else {
return;
}
}
}
char *uwsgi_queue_pop(uint64_t *size) {
struct uwsgi_queue_item *uqi;
char *ptr = (char *) uwsgi.queue;
if (uwsgi.shared->queue_pos > 0) uwsgi.shared->queue_pos--;
if (uwsgi.queue_header->pos == 0) {
uwsgi.queue_header->pos = uwsgi.queue_size-1;
}
else {
uwsgi.queue_header->pos--;
}
ptr = ptr + (uwsgi.queue_blocksize*uwsgi.shared->queue_pos);
ptr = ptr + (uwsgi.queue_blocksize*uwsgi.queue_header->pos);
uqi = (struct uwsgi_queue_item *) ptr;
if (!uqi->size) return NULL;
@@ -122,16 +117,16 @@ char *uwsgi_queue_pull(uint64_t *size) {
struct uwsgi_queue_item *uqi;
char *ptr = (char *) uwsgi.queue;
ptr = ptr + (uwsgi.queue_blocksize*uwsgi.shared->queue_pull_pos);
ptr = ptr + (uwsgi.queue_blocksize*uwsgi.queue_header->pull_pos);
uqi = (struct uwsgi_queue_item *) ptr;
if (!uqi->size) return NULL;
*size = uqi->size;
uwsgi.shared->queue_pull_pos++;
uwsgi.queue_header->pull_pos++;
if (uwsgi.shared->queue_pull_pos >= uwsgi.queue_size) uwsgi.shared->queue_pull_pos = 0;
if (uwsgi.queue_header->pull_pos >= uwsgi.queue_size) uwsgi.queue_header->pull_pos = 0;
// remove item
uqi->size = 0;
@@ -150,7 +145,7 @@ int uwsgi_queue_push(char *message, uint64_t size) {
if (!size) return 0;
ptr = ptr + (uwsgi.queue_blocksize*uwsgi.shared->queue_pos);
ptr = ptr + (uwsgi.queue_blocksize*uwsgi.queue_header->pos);
uqi = (struct uwsgi_queue_item *) ptr;
ptr += sizeof(struct uwsgi_queue_item);
@@ -159,9 +154,34 @@ int uwsgi_queue_push(char *message, uint64_t size) {
uqi->ts = time(NULL);
memcpy(ptr, message, size);
uwsgi.shared->queue_pos++;
uwsgi.queue_header->pos++;
if (uwsgi.shared->queue_pos >= uwsgi.queue_size) uwsgi.shared->queue_pos = 0;
if (uwsgi.queue_header->pos >= uwsgi.queue_size) uwsgi.queue_header->pos = 0;
return 1;
}
int uwsgi_queue_set(uint64_t pos, char *message, uint64_t size) {
struct uwsgi_queue_item *uqi;
char *ptr = (char *) uwsgi.queue;
if (size > uwsgi.queue_blocksize + sizeof(struct uwsgi_queue_item))
return 0;
if (!size) return 0;
if (pos >= uwsgi.queue_size) return 0;
ptr = ptr + (uwsgi.queue_blocksize*pos);
uqi = (struct uwsgi_queue_item *) ptr;
ptr += sizeof(struct uwsgi_queue_item);
uqi->size = size;
uqi->ts = time(NULL);
memcpy(ptr, message, size);
return 1;
}
+10 -2
View File
@@ -8,6 +8,14 @@ from setuptools.dist import Distribution
from setuptools.command.install import install
from setuptools.command.build_ext import build_ext
def get_profile():
profile = os.environ.get('UWSGI_PROFILE','buildconf/default.ini')
if not profile.endswith('.ini'):
profile = "%s.ini" % profile
if not '/' in profile:
profile = "buildconf/%s" % profile
return profile
def patch_bin_path(cmd, conf):
@@ -26,7 +34,7 @@ def patch_bin_path(cmd, conf):
class uWSGIBuilder(build_ext):
def run(self):
conf = uc.uConf('buildconf/default.ini')
conf = uc.uConf(get_profile())
patch_bin_path(self, conf)
uc.build_uwsgi( conf )
@@ -38,7 +46,7 @@ class uWSGIInstall(install):
if self.record:
record_file = open(self.record,'w')
conf = uc.uConf('buildconf/default.ini')
conf = uc.uConf(get_profile())
patch_bin_path(self, conf)
uc.build_uwsgi( conf )
+10
View File
@@ -0,0 +1,10 @@
/* this is a skeleton to use libuwsgi in external projects */
extern char **environ;
int uwsgi_init(int, char **, char **);
int main(int argc, char **argv, char **environ) {
uwsgi_init(argc, argv, environ);
}
-117
View File
@@ -350,123 +350,6 @@ static int get_snmp_integer(uint8_t * ptr, uint64_t * val) {
return size + oid_sz;
}
/*
PyObject *py_snmp_counter32(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bI:snmp_set_counter32", &oid_num, &oid_val)) {
return NULL;
}
if (oid_num > 100 || oid_num < 1)
goto clear;
uwsgi.shared->snmp_value[oid_num - 1].type = SNMP_COUNTER32;
uwsgi.shared->snmp_value[oid_num - 1].val = oid_val;
Py_INCREF(Py_True);
return Py_True;
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_snmp_counter64(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint64_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bK:snmp_set_counter64", &oid_num, &oid_val)) {
return NULL;
}
if (oid_num > 100 || oid_num < 1)
goto clear;
uwsgi.shared->snmp_value[oid_num - 1].type = SNMP_COUNTER64;
uwsgi.shared->snmp_value[oid_num - 1].val = oid_val;
Py_INCREF(Py_True);
return Py_True;
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_snmp_gauge(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bI:snmp_set_gauge", &oid_num, &oid_val)) {
return NULL;
}
if (oid_num > 100 || oid_num < 1)
goto clear;
uwsgi.shared->snmp_value[oid_num - 1].type = SNMP_GAUGE;
uwsgi.shared->snmp_value[oid_num - 1].val = oid_val;
Py_INCREF(Py_True);
return Py_True;
clear:
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_snmp_community(PyObject * self, PyObject * args) {
char *snmp_community;
if (!PyArg_ParseTuple(args, "s:snmp_set_community", &snmp_community)) {
return NULL;
}
if (strlen(snmp_community) > 72) {
uwsgi_log( "*** warning the supplied SNMP community string will be truncated to 72 chars ***\n");
memcpy(uwsgi.shared->snmp_community, snmp_community, 72);
}
else {
memcpy(uwsgi.shared->snmp_community, snmp_community, strlen(snmp_community) + 1);
}
Py_INCREF(Py_True);
return Py_True;
}
static PyMethodDef uwsgi_snmp_methods[] = {
{"snmp_set_counter32", py_snmp_counter32, METH_VARARGS, ""},
{"snmp_set_counter64", py_snmp_counter64, METH_VARARGS, ""},
{"snmp_set_gauge", py_snmp_gauge, METH_VARARGS, ""},
{"snmp_set_community", py_snmp_community, METH_VARARGS, ""},
{NULL, NULL},
};
void snmp_init() {
PyMethodDef *uwsgi_function;
for (uwsgi_function = uwsgi_snmp_methods; uwsgi_function->ml_name != NULL; uwsgi_function++) {
PyObject *func = PyCFunction_New(uwsgi_function, NULL);
PyDict_SetItemString(uwsgi.embedded_dict, uwsgi_function->ml_name, func);
Py_DECREF(func);
}
uwsgi_log( "SNMP python functions initialized.\n");
}
*/
#else
#warning "*** SNMP support is disabled ***"
#endif
+48
View File
@@ -0,0 +1,48 @@
# uwsgi --queue 10 --queue-store test.queue --master --module tests.queue --socket :3031
import uwsgi
import os
from flask import Flask,render_template,request,redirect,flash
app = Flask(__name__)
app.debug = True
app.secret_key = os.urandom(24)
@app.route('/')
def index():
return render_template('queue.html', uwsgi=uwsgi)
@app.route('/push', methods=['POST'])
def push_item():
if uwsgi.queue_push(request.form['body']):
flash('item enqueued')
return redirect('/')
else:
flash('unable to enqueue item')
return render_template('queue.html', uwsgi=uwsgi)
@app.route('/get', methods=['POST'])
def get_item():
flash( "slot %s value = %s" % (request.form['slot'], uwsgi.queue_get( int(request.form['slot']) )))
return redirect('/')
@app.route('/pop', methods=['POST'])
def pop_item():
flash( "popped value = %s" % uwsgi.queue_pop() )
return redirect('/')
@app.route('/pull', methods=['POST'])
def pull_item():
flash( "pulled value = %s" % uwsgi.queue_pull() )
return redirect('/')
@app.route('/set', methods=['POST'])
def set_item():
if uwsgi.queue_set(int(request.form['pos']), request.form['body']):
flash('item set')
return redirect('/')
else:
flash('unable to set item')
return render_template('queue.html', uwsgi=uwsgi)
+6
View File
@@ -0,0 +1,6 @@
import sys
def application(e, sr):
sr('200 OK', [('Content-Type','text/html')])
print sys.gettotalrefcount()
yield '%s' % sys.gettotalrefcount()
+16
View File
@@ -0,0 +1,16 @@
import uwsgi
uwsgi.sharedarea_writelong(173, 30)
def application(e, sr):
sr('200 Ok', [('Content-Type','text/html')])
uwsgi.sharedarea_write(17, e['REQUEST_URI'])
uwsgi.sharedarea_inclong(173)
uwsgi.sharedarea_inclong(173, 17)
yield uwsgi.sharedarea_read(17, len(e['REQUEST_URI']))
yield "<br/>"
yield str(uwsgi.sharedarea_readlong(173))
+50
View File
@@ -0,0 +1,50 @@
<head>
<style>
.flash {
color: red;
}
</style>
</head>
<body>
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="flash">
<ul>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% endwith %}
<h1>next available slot: {{uwsgi.queue_slot()}}</h1>
<h1>next available pull slot: {{uwsgi.queue_pull_slot()}}</h1>
{% for item in range(0, uwsgi.queue_size) %}
slot {{item}} = {{uwsgi.queue_get(item)}}<br/>
{% endfor %}
<br/>
<form method="POST" action="/push">
<input type="text" name="body"><input type="submit" value="push value" /><br/>
</form>
<form method="POST" action="/get">
<input type="text" name="slot" size="9"><input type="submit" value="get value" /><br/>
</form>
<form method="POST" action="/pop">
<input type="submit" value="pop value" /><br/>
</form>
<form method="POST" action="/pull">
<input type="submit" value="pull value" /><br/>
</form>
<form method="POST" action="/set">
<input type="text" name="pos" size="5" /> <input type="text" name="body"><input type="submit" value="set value" /><br/>
</form>
</body>
+48
View File
@@ -0,0 +1,48 @@
import gevent
import gevent.socket
import sys
if 'gettotalrefcount' in sys.__dict__:
REFCNT = True
else:
REFCNT = False
def bg_task():
for i in range(1,10):
print "background task", i
gevent.sleep(2)
def long_task():
for i in range(1,10):
print i
gevent.sleep()
def application(e, sr):
sr('200 OK', [('Content-Type','text/html')])
t = gevent.spawn(long_task)
t.join()
yield "sleeping for 3 seconds...<br/>"
gevent.sleep(3)
yield "done<br>"
yield "getting some ips...<br/>"
urls = ['www.google.com', 'www.example.com', 'www.python.org', 'projects.unbit.it']
jobs = [gevent.spawn(gevent.socket.gethostbyname, url) for url in urls]
gevent.joinall(jobs, timeout=2)
for j in jobs:
yield "ip = %s<br/>" % j.value
if REFCNT:
print sys.gettotalrefcount()
# this task will goes on after request end
gevent.spawn(bg_task)
+5 -9
View File
@@ -1391,14 +1391,14 @@ int count_options(struct option *lopt) {
return count;
}
int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf, size_t limit) {
int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf) {
size_t post_remains = wsgi_req->post_cl;
int ret;
ssize_t len;
char *ptr = buf;
while (post_remains) {
while (post_remains > 0) {
if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
inc_harakiri(uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
}
@@ -1413,12 +1413,8 @@ int uwsgi_read_whole_body_in_mem(struct wsgi_request *wsgi_req, char *buf, size_
return 0;
}
if (limit) {
len = read(wsgi_req->poll.fd, ptr, UMIN(post_remains, limit) );
}
else {
len = read(wsgi_req->poll.fd, ptr, post_remains);
}
len = read(wsgi_req->poll.fd, ptr, post_remains);
if (len <= 0) {
uwsgi_error("read()");
return 0;
@@ -2036,7 +2032,7 @@ char *magic_sub(char *buffer, int len, int *size, char *magic_table[]) {
void init_magic_table(char *magic_table[]) {
int i;
for (i = 0; i < 0xff; i++) {
for (i = 0; i <= 0xff; i++) {
magic_table[i] = "";
}
+40 -30
View File
@@ -77,6 +77,7 @@ static struct option long_base_options[] = {
{"emperor-amqp-vhost", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_VHOST},
{"emperor-amqp-username", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_USERNAME},
{"emperor-amqp-password", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_PASSWORD},
{"emperor-throttle", required_argument, 0, LONG_ARGS_EMPEROR_THROTTLE},
{"vassals-inherit", required_argument, 0, LONG_ARGS_VASSALS_INHERIT},
{"vassals-start-hook", required_argument, 0, LONG_ARGS_VASSALS_START_HOOK},
{"vassals-stop-hook", required_argument, 0, LONG_ARGS_VASSALS_STOP_HOOK},
@@ -808,19 +809,19 @@ int main(int argc, char *argv[], char *envp[]) {
#endif
char *emperor_env;
char *magic_table[0xff];
char *optname;
signal(SIGHUP, SIG_IGN);
signal(SIGTERM, SIG_IGN);
init_magic_table(magic_table);
//initialize masterpid with a default value
masterpid = getpid();
memset(&uwsgi, 0, sizeof(struct uwsgi_server));
uwsgi.cwd = uwsgi_get_cwd();
init_magic_table(uwsgi.magic_table);
atexit(vacuum);
@@ -861,6 +862,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi.cache_server_fd = -1;
uwsgi.emperor_fd_config = -1;
uwsgi.emperor_throttle = 1000;
uwsgi.emperor_pid = -1;
uwsgi.cluster_fd = -1;
@@ -971,11 +973,11 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi.hostname_len = strlen(uwsgi.hostname);
magic_table['v'] = uwsgi.cwd;
magic_table['h'] = uwsgi.hostname;
uwsgi.magic_table['v'] = uwsgi.cwd;
uwsgi.magic_table['h'] = uwsgi.hostname;
#ifdef UWSGI_EMBED_CONFIG
uwsgi_ini_config("", magic_table);
uwsgi_ini_config("", uwsgi.magic_table);
#endif
uwsgi.option_index = -1;
@@ -1064,36 +1066,36 @@ int main(int argc, char *argv[], char *envp[]) {
}
}
}
#ifdef UWSGI_XML
if (uwsgi.xml_config != NULL) {
config_magic_table_fill(uwsgi.xml_config, magic_table);
uwsgi_xml_config(uwsgi.xml_config, uwsgi.wsgi_req, 0, magic_table);
uwsgi.xml_config = magic_table['p'];
config_magic_table_fill(uwsgi.xml_config, uwsgi.magic_table);
uwsgi_xml_config(uwsgi.xml_config, uwsgi.wsgi_req, 0, uwsgi.magic_table);
uwsgi.xml_config = uwsgi.magic_table['p'];
}
#endif
#ifdef UWSGI_INI
if (uwsgi.ini != NULL) {
config_magic_table_fill(uwsgi.ini, magic_table);
uwsgi_ini_config(uwsgi.ini, magic_table);
config_magic_table_fill(uwsgi.ini, uwsgi.magic_table);
uwsgi_ini_config(uwsgi.ini, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_YAML
if (uwsgi.yaml != NULL) {
config_magic_table_fill(uwsgi.yaml, magic_table);
uwsgi_yaml_config(uwsgi.yaml, magic_table);
config_magic_table_fill(uwsgi.yaml, uwsgi.magic_table);
uwsgi_yaml_config(uwsgi.yaml, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_JSON
if (uwsgi.json != NULL) {
config_magic_table_fill(uwsgi.json, magic_table);
uwsgi_json_config(uwsgi.json, magic_table);
config_magic_table_fill(uwsgi.json, uwsgi.magic_table);
uwsgi_json_config(uwsgi.json, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_SQLITE3
if (uwsgi.sqlite3 != NULL) {
config_magic_table_fill(uwsgi.sqlite3, magic_table);
uwsgi_sqlite3_config(uwsgi.sqlite3, magic_table);
config_magic_table_fill(uwsgi.sqlite3, uwsgi.magic_table);
uwsgi_sqlite3_config(uwsgi.sqlite3, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_LDAP
@@ -1110,36 +1112,36 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi_log("using %s as config template\n", uct->filename);
#ifdef UWSGI_XML
if (!strcmp(uct->filename + strlen(uct->filename) - 4, ".xml")) {
uwsgi_xml_config(uct->filename, uwsgi.wsgi_req, 0, magic_table);
uwsgi_xml_config(uct->filename, uwsgi.wsgi_req, 0, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_INI
if (!strcmp(uct->filename + strlen(uct->filename) - 4, ".ini")) {
uwsgi_ini_config(uct->filename, magic_table);
uwsgi_ini_config(uct->filename, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_YAML
if (!strcmp(uct->filename + strlen(uct->filename) - 4, ".yml")) {
uwsgi_yaml_config(uct->filename, magic_table);
uwsgi_yaml_config(uct->filename, uwsgi.magic_table);
}
if (!strcmp(uct->filename + strlen(uct->filename) - 5, ".yaml")) {
uwsgi_yaml_config(uct->filename, magic_table);
uwsgi_yaml_config(uct->filename, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_JSON
if (!strcmp(uct->filename + strlen(uct->filename) - 3, ".js")) {
uwsgi_json_config(uct->filename, magic_table);
uwsgi_json_config(uct->filename, uwsgi.magic_table);
}
#endif
#ifdef UWSGI_SQLITE3
if (!strcmp(uct->filename + strlen(uct->filename) - 3, ".db")) {
uwsgi_sqlite3_config(uct->filename, magic_table);
uwsgi_sqlite3_config(uct->filename, uwsgi.magic_table);
}
if (!strcmp(uct->filename + strlen(uct->filename) - 7, ".sqlite")) {
uwsgi_sqlite3_config(uct->filename, magic_table);
uwsgi_sqlite3_config(uct->filename, uwsgi.magic_table);
}
if (!strcmp(uct->filename + strlen(uct->filename) - 8, ".sqlite3")) {
uwsgi_sqlite3_config(uct->filename, magic_table);
uwsgi_sqlite3_config(uct->filename, uwsgi.magic_table);
}
#endif
uct = uct->next;
@@ -1578,15 +1580,16 @@ int uwsgi_start(void *v_argv) {
if (uwsgi.post_buffering > 0) {
uwsgi.async_post_buf = uwsgi_malloc(sizeof(char *) * uwsgi.cores);
uwsgi.mem_post_buf = uwsgi_malloc(sizeof(char *) * uwsgi.cores);
if (!uwsgi.post_buffering_bufsize) {
if (!uwsgi.post_buffering_bufsize)
uwsgi.post_buffering_bufsize = 8192;
if (uwsgi.post_buffering_bufsize < uwsgi.post_buffering) {
uwsgi.post_buffering_bufsize = uwsgi.post_buffering;
uwsgi_log("setting request body buffering size to %d bytes\n", uwsgi.post_buffering_bufsize);
}
}
for (i = 0; i < uwsgi.cores; i++) {
uwsgi.async_buf[i] = uwsgi_malloc(uwsgi.buffer_size);
if (uwsgi.post_buffering > 0) {
uwsgi.mem_post_buf[i] = uwsgi_malloc(uwsgi.post_buffering);
uwsgi.async_post_buf[i] = uwsgi_malloc(uwsgi.post_buffering_bufsize);
}
}
@@ -1654,18 +1657,18 @@ int uwsgi_start(void *v_argv) {
uwsgi_lock_init(uwsgi.rpc_table_lock);
if (uwsgi.sharedareasize > 0) {
uwsgi.sharedareamutex = uwsgi_mmap_shared_lock();
uwsgi.sharedarea = mmap(NULL, uwsgi.page_size * uwsgi.sharedareasize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
if (uwsgi.sharedarea) {
uwsgi_log("shared area mapped at %p, you can access it with uwsgi.sharedarea* functions.\n", uwsgi.sharedarea);
uwsgi_lock_init(uwsgi.sharedareamutex);
}
else {
uwsgi_error("mmap()");
exit(1);
}
uwsgi.sa_lock = uwsgi_mmap_shared_rwlock();
uwsgi_rwlock_init(uwsgi.sa_lock);
}
if (uwsgi.queue_size > 0) {
@@ -2575,6 +2578,10 @@ void uwsgi_ignition() {
if (uwsgi.loop) {
void (*u_loop) (void) = uwsgi_get_loop(uwsgi.loop);
if (!u_loop) {
uwsgi_log("unavailable loop engine !!!\n");
exit(1);
}
uwsgi_log("running %s loop %p\n", uwsgi.loop, u_loop);
u_loop();
uwsgi_log("done\n");
@@ -2742,6 +2749,9 @@ static int manage_base_opt(int i, char *optarg) {
case LONG_ARGS_EMPEROR_BROODLORD:
uwsgi.emperor_broodlord = atoi(optarg);
return 1;
case LONG_ARGS_EMPEROR_THROTTLE:
uwsgi.emperor_throttle = atoi(optarg);
return 1;
case LONG_ARGS_EMPEROR:
uwsgi.emperor_dir = optarg;
return 1;
+15 -8
View File
@@ -323,6 +323,11 @@ struct uwsgi_daemon {
//int pipe[2];
};
struct uwsgi_queue_header {
uint64_t pos;
uint64_t pull_pos;
};
struct uwsgi_queue_item {
uint64_t size;
time_t ts;
@@ -480,6 +485,7 @@ struct uwsgi_opt {
#define LONG_ARGS_HTTP_SOCKET 17132
#define LONG_ARGS_FASTCGI_SOCKET 17133
#define LONG_ARGS_THREADS_STACKSIZE 17134
#define LONG_ARGS_EMPEROR_THROTTLE 17135
#define UWSGI_OK 0
@@ -930,6 +936,7 @@ struct uwsgi_server {
int emperor_fd;
int emperor_fd_config;
int early_emperor;
int emperor_throttle;
char *emperor_dir;
pid_t emperor_pid;
int emperor_broodlord;
@@ -1015,7 +1022,6 @@ struct uwsgi_server {
struct iovec **async_hvec;
char **async_buf;
char **async_post_buf;
char **mem_post_buf;
struct wsgi_request **async_waiting_fd_table;
struct wsgi_request **async_proto_fd_table;
@@ -1097,6 +1103,8 @@ struct uwsgi_server {
int harakiri_verbose;
char *magic_table[256];
int numproc;
int async;
int async_running;
@@ -1109,8 +1117,7 @@ struct uwsgi_server {
int vec_size;
char *sharedarea;
void *sharedareamutex;
int sharedareasize;
uint64_t sharedareasize;
#ifdef UWSGI_THREADING
pthread_mutex_t six_feet_under_lock;
@@ -1300,6 +1307,7 @@ struct uwsgi_server {
uint64_t queue_size;
uint64_t queue_blocksize;
void *queue;
struct uwsgi_queue_header *queue_header;
char *queue_store;
size_t queue_filesize;
int queue_store_sync;
@@ -1315,6 +1323,7 @@ struct uwsgi_server {
void *rb_timer_table_lock;
void *cron_table_lock;
void *rpc_table_lock;
void *sa_lock;
#ifdef UWSGI_SPOOLER
void *spooler_lock;
#endif
@@ -1440,8 +1449,6 @@ struct uwsgi_shared {
uint64_t cache_first_available_item;
uint64_t cache_unused_stack_ptr;
uint64_t queue_pos;
uint64_t queue_pull_pos;
int worker_signal_pipe[2];
#ifdef UWSGI_SPOOLER
@@ -1720,7 +1727,7 @@ struct wsgi_request *threaded_current_wsgi_req(void);
void build_options(void);
int uwsgi_read_whole_body(struct wsgi_request *, char *, size_t);
int uwsgi_read_whole_body_in_mem(struct wsgi_request *, char *, size_t);
int uwsgi_read_whole_body_in_mem(struct wsgi_request *, char *);
ssize_t uwsgi_sendfile(struct wsgi_request *);
@@ -1867,6 +1874,8 @@ void uwsgi_init_cache(void);
char *uwsgi_queue_get(uint64_t, uint64_t *);
char *uwsgi_queue_pull(uint64_t *);
int uwsgi_queue_push(char *, uint64_t);
char *uwsgi_queue_pop(uint64_t *);
int uwsgi_queue_set(uint64_t, char *, uint64_t);
// maintain alignment here !!!
struct uwsgi_dict_item {
@@ -1993,8 +2002,6 @@ inline int event_queue_write(void);
void uwsgi_help(void);
void uwsgi_queue_fix(void);
int uwsgi_str2_num(char *);
int uwsgi_str3_num(char *);
int uwsgi_str4_num(char *);
+13 -5
View File
@@ -182,7 +182,10 @@ def build_uwsgi(uc):
if bin_name.find("/") < 0:
bin_name = './' + bin_name
print("*** uWSGI is ready, launch it with %s ***" % bin_name)
if uc.get('as_shared_library'):
print("*** uWSGI shared library (%s) is ready, move it to a library directory ***" % bin_name)
else:
print("*** uWSGI is ready, launch it with %s ***" % bin_name)
class uConf(object):
@@ -190,6 +193,8 @@ class uConf(object):
def __init__(self, filename):
self.config = ConfigParser.ConfigParser()
print("using profile: %s" % filename)
if not os.path.exists(filename):
raise Exception("profile not found !!!")
self.config.read(filename)
self.gcc_list = ['utils', 'protocol', 'socket', 'logging', 'master', 'master_utils', 'emperor', 'notify',
'plugins', 'lock', 'cache', 'queue', 'event', 'signal', 'rpc', 'gateway', 'loop', 'lib/rbtree', 'lib/amqp', 'rb_timers', 'uwsgi']
@@ -342,7 +347,10 @@ class uConf(object):
k_all = uwsgi_os_k.split('.')
k_base = k_all[0]
k_major = k_all[1]
k_minor = k_all[2]
if len(k_all) > 2:
k_minor = k_all[2]
else:
k_minor = 0
if int(k_base) > 2:
timer_mode = 'timerfd'
elif int(k_minor) >= 25:
@@ -719,13 +727,13 @@ if __name__ == "__main__":
if cmd == '--libs':
print(' '.join(libs))
elif cmd == '--build':
bconf = 'default.ini'
bconf = os.environ.get('UWSGI_PROFILE','default.ini')
try:
bconf = sys.argv[2]
if not bconf.endswith('.ini'):
bconf += '.ini'
except:
pass
if not bconf.endswith('.ini'):
bconf += '.ini'
if not '/' in bconf:
bconf = 'buildconf/%s' % bconf
build_uwsgi(uConf(bconf))
+57
View File
@@ -0,0 +1,57 @@
import uwsgi
import os
def xsendfile(e, sr):
sr('200 OK', [('Content-Type', 'image/png'), ('X-Sendfile', os.path.abspath('logo_uWSGI.png'))])
return b''
def serve_logo(e, sr):
sr('200 OK', [('Content-Type', 'image/png')])
return uwsgi.sendfile('logo_uWSGI.png')
def serve_options(e, sr):
sr('200 OK', [('Content-Type', 'text/html')])
for opt in range(0,256):
body = "{opt} = {optvalue}<br/>".format(opt=opt, optvalue=uwsgi.get_option(opt))
yield bytes(body.encode('ascii'))
def serve_config(e, sr):
sr('200 OK', [('Content-Type', 'text/html')])
for opt in uwsgi.opt.keys():
body = "{opt} = {optvalue}<br/>".format(opt=opt, optvalue=uwsgi.opt[opt].decode('ascii'))
yield bytes(body.encode('ascii'))
routes = {}
routes['/xsendfile'] = xsendfile
routes['/logo'] = serve_logo
routes['/config'] = serve_config
routes['/options'] = serve_options
def application(env, start_response):
if env['PATH_INFO'] in routes:
return routes[env['PATH_INFO']](env, start_response)
start_response('200 OK', [('Content-Type', 'text/html')])
body = """
<img src="/logo"/> version {version}<br/>
<hr size="1"/>
Configuration<br/>
<iframe src="/config"></iframe><br/>
<br/>
Dynamic options<br/>
<iframe src="/options"></iframe><br/>
""".format(version=uwsgi.version.decode('ascii'))
return bytes(body.encode('ascii'))
+3 -3
View File
@@ -141,12 +141,12 @@ void uwsgi_xml_config(char *filename, struct wsgi_request *wsgi_req, int app_tag
if (node->type == XML_ELEMENT_NODE) {
if (!strcmp((char *) node->name, "app")) {
wsgi_req->script_name_len = 0;
wsgi_req->appid_len = 0;
wsgi_req->host_len = 0;
xml_uwsgi_mountpoint = xmlGetProp(node, (const xmlChar *) "mountpoint");
if (xml_uwsgi_mountpoint) {
wsgi_req->script_name = (char *) xml_uwsgi_mountpoint;
wsgi_req->script_name_len = strlen(wsgi_req->script_name);
wsgi_req->appid = (char *) xml_uwsgi_mountpoint;
wsgi_req->appid_len = strlen(wsgi_req->appid);
}
xml_uwsgi_domain = xmlGetProp(node, (const xmlChar *) "domain");