From 0d9fe39dbbcf9dadfc10d1bad8e68f50eb839045 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka <valenok@gmail.com> Date: Wed, 25 Jun 2014 11:43:07 +0100 Subject: [PATCH] ns_read_from_socket(): calling recv() in a loop until failure --- mongoose.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mongoose.c b/mongoose.c index 5d7b90091..ef3e98b17 100644 --- a/mongoose.c +++ b/mongoose.c @@ -756,6 +756,7 @@ static void ns_read_from_socket(struct ns_connection *conn) { // Therefore, read in a loop until we read everything. Without the loop, // we skip to the next select() cycle which can just timeout. while ((n = SSL_read(conn->ssl, buf, sizeof(buf))) > 0) { + DBG(("%p %d <- %d bytes (SSL)", conn, conn->flags, n)); iobuf_append(&conn->recv_iobuf, buf, n); ns_call(conn, NS_RECV, &n); } @@ -778,16 +779,15 @@ static void ns_read_from_socket(struct ns_connection *conn) { } else #endif { - n = recv(conn->sock, buf, sizeof(buf), 0); + while ((n = recv(conn->sock, buf, sizeof(buf), 0)) > 0) { + DBG(("%p %d <- %d bytes (PLAIN)", conn, conn->flags, n)); + iobuf_append(&conn->recv_iobuf, buf, n); + ns_call(conn, NS_RECV, &n); + } } - DBG(("%p %d <- %d bytes", conn, conn->flags, n)); - if (ns_is_error(n)) { conn->flags |= NSF_CLOSE_IMMEDIATELY; - } else if (n > 0) { - iobuf_append(&conn->recv_iobuf, buf, n); - ns_call(conn, NS_RECV, &n); } } -- GitLab