Subject: [PATCH] Fix for close ack sending
authorAndrejs Hanins <ahanins@gmail.com>
Fri, 6 Nov 2015 16:18:32 +0000 (18:18 +0200)
committerAndy Green <andy.green@linaro.org>
Fri, 6 Nov 2015 23:04:46 +0000 (07:04 +0800)
It was forgotten in two places that pending close ack should be
processed when wsi state is WSI_STATE_RETURNED_CLOSE_ALREADY, but
not WSI_STATE_ESTABLISHED. As a result, close ack wasn't sent out
to the peer.

lib/output.c
lib/service.c

index 977d1de..44b2ab7 100644 (file)
@@ -270,7 +270,9 @@ LWS_VISIBLE int libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf,
 
        /* websocket protocol, either binary or text */
 
-       if (wsi->state != WSI_STATE_ESTABLISHED)
+       if (wsi->state != WSI_STATE_ESTABLISHED &&
+           !(wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY &&
+             protocol == LWS_WRITE_CLOSE))
                return -1;
 
        /* if we are continuing a frame that already had its header done */
index 1571a19..32e0902 100644 (file)
@@ -93,8 +93,10 @@ lws_handle_POLLOUT_event(struct libwebsocket_context *context,
 #endif
        /* pending control packets have next priority */
        
-       if (wsi->state == WSI_STATE_ESTABLISHED &&
-           wsi->u.ws.ping_pending_flag) {
+       if ((wsi->state == WSI_STATE_ESTABLISHED &&
+            wsi->u.ws.ping_pending_flag) ||
+           (wsi->state == WSI_STATE_RETURNED_CLOSE_ALREADY &&
+            wsi->u.ws.payload_is_close)) {
 
                if (wsi->u.ws.payload_is_close)
                        write_type = LWS_WRITE_CLOSE;