From 9db8925846bf9de502b0fe827964991524456d89 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 2 Jun 2025 15:55:19 -0400 Subject: [PATCH] MT#55283 handle lws partial writes Looks like partial writes are handled automatically internally, but add a request for a "writeable" callback anyway so we know when we can write more. Closes #1943 Change-Id: I86a8e1924febc0524b90dc6559753e12e0de9dfb --- daemon/websocket.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/daemon/websocket.c b/daemon/websocket.c index faf750710..af2170487 100644 --- a/daemon/websocket.c +++ b/daemon/websocket.c @@ -328,16 +328,19 @@ static int websocket_dequeue(struct websocket_conn *wc) { if (to_send) { if (to_send > 10000) - ilogs(http, LOG_DEBUG, "Writing %lu bytes to LWS", (unsigned long) to_send); + ilogs(http, LOG_DEBUG, "Writing %zu bytes to LWS", to_send); else ilogs(http, LOG_DEBUG, "Writing back to LWS: '%.*s'", (int) to_send, wo->str->str + LWS_PRE); ssize_t ret = lws_write(wsi, (unsigned char *) wo->str->str + LWS_PRE, to_send, wo->protocol); - if (ret != to_send) - ilogs(http, LOG_ERR, "Invalid LWS write: %lu != %lu", - (unsigned long) ret, - (unsigned long) to_send); + if (ret <= 0) + ilogs(http, LOG_DEBUG, "Failed LWS write: %zd", ret); + else if (ret < to_send) { + lws_callback_on_writable(wsi); + websocket_output_free(wo); + break; + } if (wo->protocol == LWS_WRITE_HTTP) is_http = true;