added mule messaging subsystem

This commit is contained in:
roberto@debian32
2011-10-03 07:45:18 +02:00
parent 9796e05ca1
commit dce3263ee3
8 changed files with 177 additions and 25 deletions
+15 -10
View File
@@ -525,11 +525,8 @@ void init_uwsgi_embedded_module() {
}
}
uwsgi_log("getting exported opts\n");
PyObject *py_opt_dict = PyDict_New();
for (i = 0; i < uwsgi.exported_opts_cnt; i++) {
uwsgi_log("%s = %s\n", uwsgi.exported_opts[i]->key, uwsgi.exported_opts[i]->value);
if (PyDict_Contains(py_opt_dict, PyString_FromString(uwsgi.exported_opts[i]->key))) {
PyObject *py_opt_item = PyDict_GetItemString(py_opt_dict, uwsgi.exported_opts[i]->key);
if (PyList_Check(py_opt_item)) {
@@ -563,8 +560,6 @@ void init_uwsgi_embedded_module() {
}
}
uwsgi_log("DONE\n");
if (PyDict_SetItemString(up.embedded_dict, "opt", py_opt_dict)) {
PyErr_Print();
exit(1);
@@ -910,9 +905,7 @@ void uwsgi_python_init_apps() {
#endif
}
uwsgi_log("init_pyargv\n");
init_pyargv();
uwsgi_log("init_pyargv\n");
#ifndef UWSGI_PYPY
#ifdef UWSGI_EMBEDDED
@@ -920,7 +913,6 @@ void uwsgi_python_init_apps() {
#endif
#endif
uwsgi_log("init_pyargv\n");
#ifdef __linux__
#if !defined(PYTHREE) && !defined(UWSGI_PYPY)
@@ -935,8 +927,6 @@ void uwsgi_python_init_apps() {
exit(1);
}
uwsgi_log("init_pyargv\n");
init_uwsgi_vars();
// setup app loaders
@@ -1404,6 +1394,19 @@ void uwsgi_python_hijack(void) {
#endif
}
int uwsgi_python_mule(char *opt) {
if (uwsgi_endswith(opt, ".py")) {
UWSGI_GET_GIL;
uwsgi_pyimport_by_filename("__main__", opt);
UWSGI_RELEASE_GIL;
return 1;
}
return 0;
}
struct uwsgi_plugin python_plugin = {
.name = "python",
@@ -1440,6 +1443,8 @@ struct uwsgi_plugin python_plugin = {
.signal_handler = uwsgi_python_signal_handler,
.rpc = uwsgi_python_rpc,
.mule = uwsgi_python_mule,
.spooler = uwsgi_python_spooler,
.code_string = uwsgi_python_code_string,
+49
View File
@@ -1050,6 +1050,52 @@ PyObject *py_uwsgi_embedded_data(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_mule_msg(PyObject * self, PyObject * args) {
char *message = NULL;
Py_ssize_t message_len = 0;
int mule_id = 0;
ssize_t len;
if (!PyArg_ParseTuple(args, "s#|i:mule_msg", &message, &message_len, &mule_id)) {
return NULL;
}
if (mule_id == 0) {
}
else if (mule_id > 0 && mule_id <= uwsgi.mules_cnt) {
len = write(uwsgi.mules[mule_id-1].queue_pipe[0], message, message_len);
if (len <= 0) {
uwsgi_error("write()");
}
}
Py_INCREF(Py_None);
return Py_None;
}
PyObject *py_uwsgi_mule_get_msg(PyObject * self, PyObject * args) {
ssize_t len;
// this buffer will be configurable
char message[65536];
if (uwsgi.muleid == 0) {
return PyErr_Format(PyExc_ValueError, "you can receive mule messages only in a mule !!!");
}
UWSGI_RELEASE_GIL;
len = read(uwsgi.mules[uwsgi.muleid-1].queue_pipe[1], message, 65536);
UWSGI_GET_GIL;
if (len <= 0) {
uwsgi_error("read()");
Py_INCREF(Py_None);
return Py_None;
}
return PyString_FromStringAndSize(message, len);
}
PyObject *py_uwsgi_extract(PyObject * self, PyObject * args) {
char *name;
@@ -2784,6 +2830,9 @@ static PyMethodDef uwsgi_advanced_methods[] = {
{"parsefile", py_uwsgi_parse_file, METH_VARARGS, ""},
{"embedded_data", py_uwsgi_embedded_data, METH_VARARGS, ""},
{"extract", py_uwsgi_extract, METH_VARARGS, ""},
{"mule_msg", py_uwsgi_mule_msg, METH_VARARGS, ""},
{"mule_get_msg", py_uwsgi_mule_get_msg, METH_VARARGS, ""},
//{"call_hook", py_uwsgi_call_hook, METH_VARARGS, ""},
{NULL, NULL},