From 7b37e0cb8b55bab6329b5ae52e0e75e3d84d00e7 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Tue, 3 Jun 2014 17:00:52 +0100 Subject: [PATCH] Added simplistic flow control in transfer_file_data() --- mongoose.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index 24abcc53..c421938b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -4494,8 +4494,15 @@ static void close_local_endpoint(struct connection *conn) { static void transfer_file_data(struct connection *conn) { char buf[IOBUF_SIZE]; - int n = read(conn->endpoint.fd, buf, conn->cl < (int64_t) sizeof(buf) ? - (int) conn->cl : (int) sizeof(buf)); + int n; + + // If output buffer is too big, don't send anything. Wait until + // mongoose drains already buffered data to the client. + if (conn->ns_conn->send_iobuf.len > sizeof(buf) * 2) return; + + // Do not send anyt + n = read(conn->endpoint.fd, buf, conn->cl < (int64_t) sizeof(buf) ? + (int) conn->cl : (int) sizeof(buf)); if (n <= 0) { close_local_endpoint(conn);