From f6f8dbecc0478b31847fe644c0e7fb4d4d91637c Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Sun, 12 Dec 2010 11:26:14 +0100 Subject: [PATCH] better uwsgi_waitfd for nailed connections --- utils.c | 19 +++++++++++++++++-- uwsgirouter5.py | 8 +++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/utils.c b/utils.c index 6ce8988b..ad3fc721 100644 --- a/utils.c +++ b/utils.c @@ -1162,20 +1162,35 @@ int uwsgi_waitfd(int fd, int timeout) { int ret; struct pollfd upoll[1]; + char oob ; + ssize_t rlen; - upoll[0].fd = fd; - upoll[0].events = POLLIN; if (!timeout) timeout = uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]; timeout = timeout*1000; if (timeout < 0) timeout = -1; + uwsgi_log("waiting for max %d secs\n", timeout); + + upoll[0].fd = fd; + upoll[0].events = POLLIN | POLLPRI; + upoll[0].revents = 0; ret = poll(upoll, 1, timeout); if (ret < 0) { uwsgi_error("poll()"); } + else if (ret > 0) { + if (upoll[0].revents & POLLPRI) { + rlen = recv(fd, &oob, 1, MSG_OOB); + uwsgi_log("RECEIVE OOB DATA %d !!!\n", rlen); + return 0; + } + else { + return ret; + } + } return ret; } diff --git a/uwsgirouter5.py b/uwsgirouter5.py index f48626f9..402828d6 100644 --- a/uwsgirouter5.py +++ b/uwsgirouter5.py @@ -1,10 +1,12 @@ import uwsgi -fd = uwsgi.connect("127.0.0.1:3033") -uwsgi.send_message(fd, 0, 4, {"leave_open":"1"}) +fd = uwsgi.connect("192.168.173.100:3033") +for part in uwsgi.send_message(fd, 0, 4, {"leave_open":"1"}, 30): + print part def application(e,s): - for part in uwsgi.send_message(fd, 0, 4, e, 0, e['wsgi.input'].fileno(), uwsgi.cl()): + for part in uwsgi.send_message(fd, 0, 4, e, 30, e['wsgi.input'].fileno(), uwsgi.cl()): + print part yield part