From 8a81dce0c16ebffc95ca767979e7faece28b23aa Mon Sep 17 00:00:00 2001 From: Deomid Ryabkov Date: Fri, 29 Apr 2016 15:13:50 +0100 Subject: [PATCH] Handle orderly shutdown of remote sockets When getting a EOF from remote, do not close immediately, drain the send buffer. PUBLISHED_FROM=e06cdaa2abc0d67d5d88bf3e72d887590a7aeccf --- mongoose.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mongoose.c b/mongoose.c index df64b640..b2f6d9f7 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3429,7 +3429,10 @@ static void mg_read_from_socket(struct mg_connection *conn) { } else { MG_FREE(buf); } - if (mg_is_error(n)) { + if (n == 0) { + /* Orderly shutdown of the socket, try flushing output. */ + conn->flags |= MG_F_SEND_AND_CLOSE; + } else if (mg_is_error(n)) { conn->flags |= MG_F_CLOSE_IMMEDIATELY; } }