From 2b19029dd01ec23a10651850288919ea3b254977 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Tue, 25 Oct 2011 17:46:41 +0200 Subject: [PATCH] multiple mule_msg() --- plugins/python/uwsgi_pymodule.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 69e0dc07..8144b776 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -1180,18 +1180,34 @@ PyObject *py_uwsgi_mule_msg(PyObject * self, PyObject * args) { PyObject *py_uwsgi_mule_get_msg(PyObject * self, PyObject * args) { - ssize_t len; + ssize_t len = 0; // this buffer will be configurable char message[65536]; + struct pollfd mulepoll[2]; 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); + mulepoll[0].fd = uwsgi.mules[uwsgi.muleid-1].queue_pipe[1]; + mulepoll[0].events = POLLIN; + mulepoll[1].fd = uwsgi.shared->mule_queue_pipe[1]; + mulepoll[1].events = POLLIN; + int ret = poll(mulepoll, 2, -1); + if (ret <= 0) { + uwsgi_error("poll"); + } + else { + if (mulepoll[0].revents & POLLIN) { + len = read(uwsgi.mules[uwsgi.muleid-1].queue_pipe[1], message, 65536); + } + else if (mulepoll[1].revents & POLLIN) { + len = read(uwsgi.shared->mule_queue_pipe[1], message, 65536); + } + } UWSGI_GET_GIL; if (len <= 0) { - uwsgi_error("read()"); + if (len < 0) uwsgi_error("read()"); Py_INCREF(Py_None); return Py_None; }