From 2488c46c9bbed0ff5f1438f8709421effe4b224b Mon Sep 17 00:00:00 2001
From: Andy Green <andy.green@linaro.org>
Date: Fri, 16 Oct 2015 11:07:52 +0800
Subject: [PATCH] attempt to get correct close flow banning writeable cb when
 closing

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

diff --git a/lib/service.c b/lib/service.c
index a17496e7..1571a198 100644
--- a/lib/service.c
+++ b/lib/service.c
@@ -117,6 +117,11 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
 		return 0;
 	}
 
+	/* if we are closing, don't confuse the user with writeable cb */
+
+	if (wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY)
+		goto user_service;
+	
 	/* if nothing critical, user can get the callback */
 	
 	m = lws_ext_callback_for_each_active(wsi, LWS_EXT_CALLBACK_IS_WRITEABLE,
@@ -205,9 +210,8 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
 	}
 #ifndef LWS_NO_EXTENSIONS
 	wsi->extension_data_pending = 0;
-
-user_service:
 #endif
+user_service:
 	/* one shot */
 
 	if (pollfd) {
-- 
GitLab