OOB for nailed connections

This commit is contained in:
roberto@fiorenzo
2010-12-12 11:22:39 +01:00
parent 245ab6d815
commit 902991daa4
7 changed files with 31 additions and 10 deletions
-2
View File
@@ -85,12 +85,10 @@ void *simple_loop(void *arg1) {
continue;
}
uwsgi_log("accepted\n");
if (wsgi_req_recv(wsgi_req)) {
continue;
}
uwsgi_close_request(wsgi_req);
}
+3 -1
View File
@@ -10,10 +10,12 @@
<manage-script-name/>
<master/>
<processes>4</processes>
<processes>8</processes>
<!--
<vhost/>
<vhost-host/>
-->
<env>TRAC_ENV=utrac</env>
+2 -1
View File
@@ -158,13 +158,14 @@ PyObject *py_uwsgi_close(PyObject * self, PyObject * args) {
PyObject *py_uwsgi_signal(PyObject * self, PyObject * args) {
char uwsgi_signal;
ssize_t rlen;
if (!PyArg_ParseTuple(args, "B:signal", &uwsgi_signal)) {
return NULL;
}
uwsgi_log("sending %d to master\n", uwsgi_signal);
write(uwsgi.workers[uwsgi.mywid].pipe[1], &uwsgi_signal, 1);
rlen = write(uwsgi.workers[uwsgi.mywid].pipe[1], &uwsgi_signal, 1);
Py_INCREF(Py_None);
return Py_None;
+8 -4
View File
@@ -212,6 +212,12 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
}
if (wsgi_req->uh.modifier2 == 4) {
// for persistent connections
uwsgi_log("LEAVE OPEN\n");
wsgi_req->leave_open = 1;
}
if (wsgi_req->protocol_len < 5) {
@@ -274,10 +280,6 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
}
}
if (wsgi_req->uh.modifier2 == 4) {
// for persistent connections
wsgi_req->leave_open = 1;
}
if (uwsgi.post_buffering > 0 && wsgi_req->post_cl > (size_t) uwsgi.post_buffering) {
@@ -292,7 +294,9 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
}
uwsgi_log("before subhandler %d\n", wsgi_req->leave_open);
wsgi_req->async_result = wi->request_subhandler(wsgi_req, wi);
uwsgi_log("after subhandler %d\n", wsgi_req->leave_open);
if (wsgi_req->async_result) {
+1
View File
@@ -204,6 +204,7 @@ clear:
}
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
if (!wsgi_req->leave_open) {
uwsgi_log("FCLOSE()\n");
fclose(wsgi_req->async_post);
}
if (!uwsgi.post_buffering || wsgi_req->post_cl <= (size_t) uwsgi.post_buffering) {
+10 -2
View File
@@ -202,11 +202,18 @@ ssize_t uwsgi_send_message(int fd, uint8_t modifier1, uint8_t modifier2, char *m
int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header *uh, char *buffer) {
int rlen, i;
struct wsgi_request *wsgi_req = (struct wsgi_request *) uh;
if (!timeout)
timeout = 1;
/* first 4 byte header */
uwsgi_log("poll()\n");
rlen = poll(upoll, 1, timeout * 1000);
if (wsgi_req->leave_open) {
// wait for max 1 hour for the first request
uwsgi_log("ready to accept a new request on connection %d\n", wsgi_req->poll.fd);
rlen = poll(upoll, 1, 3600 * 1000);
}
else {
rlen = poll(upoll, 1, timeout * 1000);
}
if (rlen < 0) {
uwsgi_error("poll()");
exit(1);
@@ -245,6 +252,7 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header
else if (rlen <= 0) {
uwsgi_log( "invalid request header size: %d...skip\n", rlen);
close(upoll->fd);
wsgi_req->leave_open = 0;
return 0;
}
/* big endian ? */
+7
View File
@@ -348,11 +348,17 @@ void uwsgi_close_request(struct wsgi_request *wsgi_req) {
get_memusage();
uwsgi_log("LEAVE_OPEN: %d\n", wsgi_req->leave_open);
// close the connection with the webserver
if (!wsgi_req->fd_closed && !wsgi_req->leave_open) {
// NOTE, if we close the socket before receiving eventually sent data, socket layer will send a RST
uwsgi_log("CLOSE()\n");
close(wsgi_req->poll.fd);
}
else if (wsgi_req->leave_open) {
// send OOB data to signal peer of EOS
send(wsgi_req->poll.fd, "\0", 1, MSG_OOB);
}
uwsgi.workers[0].requests++;
uwsgi.workers[uwsgi.mywid].requests++;
@@ -436,6 +442,7 @@ int wsgi_req_recv(struct wsgi_request *wsgi_req) {
}
wsgi_req->async_status = uwsgi.p[wsgi_req->uh.modifier1]->request(wsgi_req);
uwsgi_log("leave_open after request %d\n", wsgi_req->leave_open);
return 0;
}