diff --git a/lib/roles/ws/ext/extension-permessage-deflate.c b/lib/roles/ws/ext/extension-permessage-deflate.c index fba11a0b0..0079b27c0 100644 --- a/lib/roles/ws/ext/extension-permessage-deflate.c +++ b/lib/roles/ws/ext/extension-permessage-deflate.c @@ -368,28 +368,36 @@ lws_extension_callback_pm_deflate(struct lws_context *context, ebuf->token = (char *)priv->tx.next_out; priv->tx.avail_out = 1 << priv->args[PMD_TX_BUF_PWR2]; - n = deflate(&priv->tx, Z_SYNC_FLUSH); - if (n == Z_STREAM_ERROR) { - lwsl_ext("%s: Z_STREAM_ERROR\n", __func__); - return -1; + if (priv->tx.avail_in) { + n = deflate(&priv->tx, Z_SYNC_FLUSH); + if (n == Z_STREAM_ERROR) { + lwsl_ext("%s: Z_STREAM_ERROR\n", __func__); + return -1; + } } if (priv->tx_held_valid) { priv->tx_held_valid = 0; - if ((int)priv->tx.avail_out == 1 << priv->args[PMD_TX_BUF_PWR2]) + if ((int)priv->tx.avail_out == + 1 << priv->args[PMD_TX_BUF_PWR2]) /* - * we can get a situation he took something in + * We can get a situation he took something in * but did not generate anything out, at the end * of a message (eg, next thing he sends is 80 * 00, a zero length FIN, like Autobahn can * send). + * * If we have come back as a FIN, we must not * place the pending trailer 00 00 FF FF, just * the 1 byte of live data */ + *(--ebuf->token) = priv->tx_held[0]; else { - /* he generated data, prepend whole pending */ + /* + * he generated some data on his own... + * prepend the whole pending + */ ebuf->token -= 5; for (n = 0; n < 5; n++) ebuf->token[n] = priv->tx_held[n]; diff --git a/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c b/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c index 79152a6a4..26ef6a046 100644 --- a/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c +++ b/minimal-examples/ws-server/minimal-ws-server-pmd-corner/protocol_lws_minimal.c @@ -222,12 +222,13 @@ callback_minimal(struct lws *wsi, enum lws_callback_reasons reason, switch (reason) { case LWS_CALLBACK_ESTABLISHED: - if (lws_hdr_copy(wsi, buf, sizeof(buf), WSI_TOKEN_GET_URI) < 0) + if (lws_hdr_copy(wsi, (char *)buf, sizeof(buf), + WSI_TOKEN_GET_URI) < 0) return -1; - pss->last = atoi(buf + 1); + pss->last = atoi((char *)buf + 1); - if (pss->last > LWS_ARRAY_SIZE(corner_lengths)) + if (pss->last > (int)LWS_ARRAY_SIZE(corner_lengths)) pss->last = 0; lws_callback_on_writable(wsi); break;