ssl and non-ssl connections are possible and may need to be treated differently
in the user code.
+int lws_partial_buffered(wsi) added... should be checked after any
+libwebsocket_write that will be followed by another libwebsocket_write inside
+the same writeable callback. If set, you can't do any more writes until the
+writeable callback is called again. If you only do one write per writeable callback,
+you can ignore this.
+
User api removal
----------------
{
return wsi->use_ssl;
}
+
+/**
+ * lws_partial_buffered() - find out if lws buffered the last write
+ * @wsi: websocket connection to check
+ *
+ * Returns 1 if you cannot use libwebsocket_write because the last
+ * write on this connection is still buffered, and can't be cleared without
+ * returning to the service loop and waiting for the connection to be
+ * writeable again.
+ *
+ * If you will try to do >1 libwebsocket_write call inside a single
+ * WRITEABLE callback, you must check this after every write and bail if
+ * set, ask for a new writeable callback and continue writing from there.
+ *
+ * This is never set at the start of a writeable callback, but any write
+ * may set it.
+ */
+
+LWS_VISIBLE int
+lws_partial_buffered(struct libwebsocket *wsi)
+{
+ return !!wsi->truncated_send_len;
+}
lws_send_pipe_choked(struct libwebsocket *wsi);
LWS_VISIBLE LWS_EXTERN int
+lws_partial_buffered(struct libwebsocket *wsi);
+
+LWS_VISIBLE LWS_EXTERN int
lws_frame_is_binary(struct libwebsocket *wsi);
LWS_VISIBLE LWS_EXTERN int
if (m) /* while still active, extend timeout */
libwebsocket_set_timeout(wsi,
PENDING_TIMEOUT_HTTP_CONTENT, 5);
+
+ /* if he has indigestion, let him clear it before eating more */
+ if (lws_partial_buffered(wsi))
+ break;
} while (!lws_send_pipe_choked(wsi));
libwebsocket_callback_on_writable(context, wsi);
break;
flush_bail:
/* true if still partial pending */
- if (lws_send_pipe_choked(wsi)) {
+ if (lws_partial_buffered(wsi)) {
libwebsocket_callback_on_writable(context, wsi);
break;
}
// lwsl_debug("tx fifo %d\n", (ringbuffer_head - pss->ringbuffer_tail) & (MAX_MESSAGE_QUEUE - 1));
- if (lws_send_pipe_choked(wsi)) {
+ if (lws_partial_buffered(wsi) || lws_send_pipe_choked(wsi)) {
libwebsocket_callback_on_writable(context, wsi);
break;
}