diff --git a/mongoose.c b/mongoose.c index 7c4e691d..75332c61 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2882,18 +2882,20 @@ static int mg_do_recv(struct mg_connection *nc) { ((nc->flags & MG_F_LISTENING) && !(nc->flags & MG_F_UDP))) { return -1; } - len = recv_avail_size(nc, len); - if (len == 0) return -2; - if (nc->recv_mbuf.size < nc->recv_mbuf.len + len) { - mbuf_resize(&nc->recv_mbuf, nc->recv_mbuf.len + len); - } - buf = nc->recv_mbuf.buf + nc->recv_mbuf.len; - len = nc->recv_mbuf.size - nc->recv_mbuf.len; - if (nc->flags & MG_F_UDP) { - res = mg_recv_udp(nc, buf, len); - } else { - res = mg_recv_tcp(nc, buf, len); - } + do { + len = recv_avail_size(nc, len); + if (len == 0) return -2; + if (nc->recv_mbuf.size < nc->recv_mbuf.len + len) { + mbuf_resize(&nc->recv_mbuf, nc->recv_mbuf.len + len); + } + buf = nc->recv_mbuf.buf + nc->recv_mbuf.len; + len = nc->recv_mbuf.size - nc->recv_mbuf.len; + if (nc->flags & MG_F_UDP) { + res = mg_recv_udp(nc, buf, len); + } else { + res = mg_recv_tcp(nc, buf, len); + } + } while (res > 0); return res; } diff --git a/src/mg_net.c b/src/mg_net.c index 97afe9ab..809895c6 100644 --- a/src/mg_net.c +++ b/src/mg_net.c @@ -565,18 +565,20 @@ static int mg_do_recv(struct mg_connection *nc) { ((nc->flags & MG_F_LISTENING) && !(nc->flags & MG_F_UDP))) { return -1; } - len = recv_avail_size(nc, len); - if (len == 0) return -2; - if (nc->recv_mbuf.size < nc->recv_mbuf.len + len) { - mbuf_resize(&nc->recv_mbuf, nc->recv_mbuf.len + len); - } - buf = nc->recv_mbuf.buf + nc->recv_mbuf.len; - len = nc->recv_mbuf.size - nc->recv_mbuf.len; - if (nc->flags & MG_F_UDP) { - res = mg_recv_udp(nc, buf, len); - } else { - res = mg_recv_tcp(nc, buf, len); - } + do { + len = recv_avail_size(nc, len); + if (len == 0) return -2; + if (nc->recv_mbuf.size < nc->recv_mbuf.len + len) { + mbuf_resize(&nc->recv_mbuf, nc->recv_mbuf.len + len); + } + buf = nc->recv_mbuf.buf + nc->recv_mbuf.len; + len = nc->recv_mbuf.size - nc->recv_mbuf.len; + if (nc->flags & MG_F_UDP) { + res = mg_recv_udp(nc, buf, len); + } else { + res = mg_recv_tcp(nc, buf, len); + } + } while (res > 0); return res; }