return 0;
+ case LWS_EXT_CALLBACK_FLUSH_PENDING_TX:
case LWS_EXT_CALLBACK_PACKET_TX_PRESEND:
/*
conn->zs_out.next_out = conn->buf;
conn->zs_out.avail_out = sizeof(conn->buf);
- n = deflate(&conn->zs_out, Z_PARTIAL_FLUSH);
+ n = Z_PARTIAL_FLUSH;
+ if (reason == LWS_EXT_CALLBACK_FLUSH_PENDING_TX)
+ n = Z_FULL_FLUSH;
+
+ n = deflate(&conn->zs_out, n);
if (n == Z_STREAM_ERROR) {
/*
* screwed.. close the connection... we will get a
int old_state;
unsigned char buf[LWS_SEND_BUFFER_PRE_PADDING + 2 +
LWS_SEND_BUFFER_POST_PADDING];
+ int ret;
+ int m;
+ struct lws_tokens eff_buf;
if (!wsi)
return;
wsi->close_reason = reason;
/*
+ * flush any tx pending from extensions, since we may send close packet
+ * if there are problems with send, just nuke the connection
+ */
+
+ ret = 1;
+ while (ret == 1) {
+
+ /* default to nobody has more to spill */
+
+ ret = 0;
+ eff_buf.token = NULL;
+ eff_buf.token_len = 0;
+
+ /* show every extension the new incoming data */
+
+ for (n = 0; n < wsi->count_active_extensions; n++) {
+ m = wsi->active_extensions[n]->callback(
+ wsi->protocol->owning_server, wsi,
+ LWS_EXT_CALLBACK_FLUSH_PENDING_TX,
+ wsi->active_extensions_user[n], &eff_buf, 0);
+ if (m < 0) {
+ fprintf(stderr, "Extension reports "
+ "fatal error\n");
+ goto just_kill_connection;
+ }
+ if (m)
+ /*
+ * at least one extension told us he has more
+ * to spill, so we will go around again after
+ */
+ ret = 1;
+ }
+
+ /* assuming they left us something to send, send it */
+
+ if (eff_buf.token_len)
+ if (lws_issue_raw(wsi, (unsigned char *)eff_buf.token,
+ eff_buf.token_len))
+ goto just_kill_connection;
+ }
+
+ /*
* signal we are closing, libsocket_write will
* add any necessary version-specific stuff. If the write fails,
* no worries we are closing anyway. If we didn't initiate this
/* else, the send failed and we should just hang up */
}
+just_kill_connection:
/*
* we won't be servicing or receiving anything further from this guy
* remove this fd from wsi mapping hashtable
LWS_EXT_CALLBACK_DESTROY,
LWS_EXT_CALLBACK_PACKET_RX_PREPARSE,
LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
+ LWS_EXT_CALLBACK_FLUSH_PENDING_TX,
};
enum libwebsocket_write_protocol {