Created
October 23, 2012 14:23
-
-
Save jasom/3939029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/connection.c b/src/connection.c | |
index af84217..a313886 100644 | |
--- a/src/connection.c | |
+++ b/src/connection.c | |
@@ -785,7 +785,10 @@ void Connection_destroy(Connection *conn) | |
bdestroy(Connection_deliver_dequeue(conn)); | |
} | |
Connection_deliver_enqueue(conn,NULL); | |
- taskyield(); | |
+ shutdown(IOBuf_fd(conn->iob),SHUT_WR); /* This should kill the deliver task */ | |
+ while(!conn->deliverTaskDone) { | |
+ taskyield(); | |
+ } | |
IOBuf_destroy(conn->iob); | |
IOBuf_destroy(conn->proxy_iob); | |
free(conn); | |
@@ -825,6 +828,9 @@ Connection *Connection_create(Server *srv, int fd, int rport, | |
conn->iob = IOBuf_create(BUFFER_SIZE, fd, IOBUF_SOCKET); | |
} | |
+ check(taskcreate(Connection_deliver_task, conn, CONNECTION_STACK) != -1, | |
+ "Failed to create connection task."); | |
+ | |
return conn; | |
error: | |
@@ -840,9 +846,6 @@ int Connection_accept(Connection *conn) | |
check(taskcreate(Connection_task, conn, CONNECTION_STACK) != -1, | |
"Failed to create connection task."); | |
- | |
- check(taskcreate(Connection_deliver_task, conn, CONNECTION_STACK) != -1, | |
- "Failed to create connection task."); | |
return 0; | |
error: | |
IOBuf_register_disconnect(conn->iob); | |
@@ -929,7 +932,8 @@ void Connection_deliver_task(void *v) | |
error: | |
bdestroy(msg); | |
if (IOBuf_fd(conn->iob) >= 0) | |
- shutdown(IOBuf_fd(conn->iob), SHUT_RDWR); | |
+ shutdown(IOBuf_fd(conn->iob), SHUT_RD); /* This will cause the conn to be torn down */ | |
+ conn->deliverTaskDone=1; | |
taskexit(0); | |
} | |
diff --git a/src/connection.h b/src/connection.h | |
index e0db049..2ff4d25 100644 | |
--- a/src/connection.h | |
+++ b/src/connection.h | |
@@ -74,6 +74,7 @@ typedef struct Connection { | |
Handler *handler; | |
volatile bstring deliverRing[DELIVER_OUTSTANDING_MSGS]; | |
volatile unsigned deliverPost,deliverAck; | |
+ volatile unsigned deliverTaskDone; | |
Rendez deliverRendez; | |
} Connection; | |
diff --git a/src/io.c b/src/io.c | |
index a543b79..6918751 100644 | |
--- a/src/io.c | |
+++ b/src/io.c | |
@@ -157,6 +157,7 @@ static ssize_t ssl_send(IOBuf *iob, char *buffer, int len) | |
{ | |
int sent = 0; | |
int total = 0; | |
+ | |
check(iob->use_ssl, "IOBuf not set up to use ssl"); | |
if(!iob->handshake_performed) { | |
@@ -177,6 +178,7 @@ static ssize_t ssl_send(IOBuf *iob, char *buffer, int len) | |
}; | |
return total; | |
+ | |
error: | |
return -1; | |
} | |
diff --git a/src/version.h b/src/version.h | |
index 70ff605..e518f7e 100644 | |
--- a/src/version.h | |
+++ b/src/version.h | |
@@ -1,3 +1,3 @@ | |
-#define VERSION "Mongrel2/1.8.0" | |
+#define VERSION "Mongrel2/1.8.1" | |
diff --git a/tests/io_tests.c b/tests/io_tests.c | |
index c55ef70..d36e87e 100644 | |
--- a/tests/io_tests.c | |
+++ b/tests/io_tests.c | |
@@ -17,6 +17,7 @@ Connection *fake_conn(const char *file, int mode) { | |
conn->iob = IOBuf_create(10 * 1024, fd, IOBUF_FILE); | |
assert(conn->iob && "Failed to create iobuffer."); | |
conn->type = CONN_TYPE_HTTP; | |
+ conn->deliverTaskDone=1; | |
Register_connect(fd, conn); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment