From f4ffc1e2157afce80f293b3b0e8f1e907c15572b Mon Sep 17 00:00:00 2001
From: Andy Green <andy.green@linaro.org>
Date: Thu, 10 Apr 2014 17:06:59 +0800
Subject: [PATCH] fixes for close flush

Signed-off-by: Andy Green <andy.green@linaro.org>
---
 lib/output.c  | 3 ++-
 lib/service.c | 7 ++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/output.c b/lib/output.c
index b2359549..28e15a6d 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -153,9 +153,10 @@ handle_truncated_send:
 			lwsl_info("***** %x partial send completed\n", wsi);
 			/* done with it, but don't free it */
 			n = real_len;
-			if (wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE)
+			if (wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
 				lwsl_info("***** %x signalling to close now\n", wsi);
 				return -1; /* retry closing now */
+			}
 		}
 		/* always callback on writeable */
 		libwebsocket_callback_on_writable(
diff --git a/lib/service.c b/lib/service.c
index 85b6753d..9aa743e5 100644
--- a/lib/service.c
+++ b/lib/service.c
@@ -42,7 +42,12 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
 		}
 		/* leave POLLOUT active either way */
 		return 0;
-	}
+	} else
+		if (wsi->state == WSI_STATE_FLUSHING_STORED_SEND_BEFORE_CLOSE) {
+			lwsl_info("***** %x signalling to close in POLLOUT handler\n", wsi);
+			return -1; /* retry closing now */
+		}
+
 
 	m = lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_IS_WRITEABLE,
 								       NULL, 0);
-- 
GitLab