From 9c71b39eddd042ee4debb0b3f05fd7a8540226d4 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Mon, 13 Jun 2011 09:07:49 +0200 Subject: [PATCH] fixed rpc --- plugins/python/uwsgi_pymodule.c | 9 ++++++++- uwsgicc/__init__.py | 7 +++++++ uwsgicc/templates/index.html | 2 +- uwsgicc/uwsgicc.py | 3 +-- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index e731b0e1..9b1b4b63 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -317,6 +317,7 @@ PyObject *py_uwsgi_rpc(PyObject * self, PyObject * args) { uint16_t pktsize = 0, ulen; char *bufptr; int rlen; + int rpc_args = 0; struct pollfd upoll; @@ -342,10 +343,16 @@ PyObject *py_uwsgi_rpc(PyObject * self, PyObject * args) { for (i = 0; i < (argc - 2); i++) { argv[i] = PyString_AsString(PyTuple_GetItem(args, i + 2)); + rpc_args++; } if (!strcmp(node, "")) { - size = uwsgi_rpc(func, 0, NULL, buffer); + if (!rpc_args) { + size = uwsgi_rpc(func, 0, NULL, buffer); + } + else { + size = uwsgi_rpc(func, rpc_args, argv, buffer); + } } else { diff --git a/uwsgicc/__init__.py b/uwsgicc/__init__.py index f2ce560d..6b49893f 100644 --- a/uwsgicc/__init__.py +++ b/uwsgicc/__init__.py @@ -1,3 +1,10 @@ from uwsgicc import app +import uwsgi + +def hello_world(name): + return "Hello World %s" % name + +uwsgi.register_rpc("hello", hello_world) + application = app diff --git a/uwsgicc/templates/index.html b/uwsgicc/templates/index.html index 014304c2..008f9dbe 100644 --- a/uwsgicc/templates/index.html +++ b/uwsgicc/templates/index.html @@ -152,7 +152,7 @@ $(document).ready(function() { }); $('#rpc_form').submit(function() { - $.post('{{url_for('rpc')}}', { node: '192.168.173.100:3031', func: 'hello', args: ''}, function(data) { + $.post('{{url_for('rpc')}}', { node: $('[name=node]').val(), func: $('[name=func]').val(), args: $('[name=args]').val()}, function(data) { $('#dialog-modal').html(data); $('#dialog-modal').attr('title', 'RPC "hello" returned:'); $('#dialog-modal').dialog({ diff --git a/uwsgicc/uwsgicc.py b/uwsgicc/uwsgicc.py index c82481cd..ca511148 100644 --- a/uwsgicc/uwsgicc.py +++ b/uwsgicc/uwsgicc.py @@ -26,13 +26,12 @@ def log(): @app.route("/rpc", methods=['POST']) def rpc(): node = str(request.form['node']) - if node == '': - node = None fargs = str(request.form['args']) args = fargs.split() + if len(args) > 0: ret = uwsgi.rpc(str(node), str(request.form['func']), *map(str, args)) else: