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.
/* 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 */
#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;