Commit 3130e592 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Cesanta Bot

Stop reading if connection is closing

CL: none

PUBLISHED_FROM=3b74ca02e2960bbbf130f6d95aef679f2917e824
parent 93286836
...@@ -2895,7 +2895,7 @@ static int mg_do_recv(struct mg_connection *nc) { ...@@ -2895,7 +2895,7 @@ static int mg_do_recv(struct mg_connection *nc) {
} else { } else {
res = mg_recv_tcp(nc, buf, len); res = mg_recv_tcp(nc, buf, len);
} }
} while (res > 0); } while (res > 0 && !(nc->flags & (MG_F_CLOSE_IMMEDIATELY | MG_F_UDP)));
return res; return res;
} }
...@@ -3012,8 +3012,10 @@ static int mg_recv_udp(struct mg_connection *nc, char *buf, size_t len) { ...@@ -3012,8 +3012,10 @@ static int mg_recv_udp(struct mg_connection *nc, char *buf, size_t len) {
mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, n, MG_EV_RECV); mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, n, MG_EV_RECV);
} }
#endif #endif
if (n != 0) {
mg_call(nc, NULL, nc->user_data, MG_EV_RECV, &n); mg_call(nc, NULL, nc->user_data, MG_EV_RECV, &n);
} }
}
out: out:
mbuf_free(&lc->recv_mbuf); mbuf_free(&lc->recv_mbuf);
......
...@@ -578,7 +578,7 @@ static int mg_do_recv(struct mg_connection *nc) { ...@@ -578,7 +578,7 @@ static int mg_do_recv(struct mg_connection *nc) {
} else { } else {
res = mg_recv_tcp(nc, buf, len); res = mg_recv_tcp(nc, buf, len);
} }
} while (res > 0); } while (res > 0 && !(nc->flags & (MG_F_CLOSE_IMMEDIATELY | MG_F_UDP)));
return res; return res;
} }
...@@ -695,8 +695,10 @@ static int mg_recv_udp(struct mg_connection *nc, char *buf, size_t len) { ...@@ -695,8 +695,10 @@ static int mg_recv_udp(struct mg_connection *nc, char *buf, size_t len) {
mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, n, MG_EV_RECV); mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, n, MG_EV_RECV);
} }
#endif #endif
if (n != 0) {
mg_call(nc, NULL, nc->user_data, MG_EV_RECV, &n); mg_call(nc, NULL, nc->user_data, MG_EV_RECV, &n);
} }
}
out: out:
mbuf_free(&lc->recv_mbuf); mbuf_free(&lc->recv_mbuf);
......
...@@ -5665,7 +5665,7 @@ static const char *test_socks(void) { ...@@ -5665,7 +5665,7 @@ static const char *test_socks(void) {
mbuf_resize(&c->recv_mbuf, 10000000); mbuf_resize(&c->recv_mbuf, 10000000);
/* Run event loop. Use more cycles to let file download complete. */ /* Run event loop. Use more cycles to let file download complete. */
poll_until(&mgr, 10, c_str_ne, status, (void *) ""); poll_until(&mgr, 15, c_str_ne, status, (void *) "");
ASSERT_STREQ(status, "success"); ASSERT_STREQ(status, "success");
mg_mgr_free(&mgr); mg_mgr_free(&mgr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment