better uwsgi_waitfd for nailed connections

This commit is contained in:
roberto@sirius
2010-12-12 11:26:14 +01:00
parent 902991daa4
commit f6f8dbecc0
2 changed files with 22 additions and 5 deletions
+17 -2
View File
@@ -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;
}
+5 -3
View File
@@ -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