From fc1b05ae323d0e67163bbcfbab6b536ae0c62a23 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 7 Feb 2025 15:39:34 +0000 Subject: [PATCH] xfer: Be patient when the websocket buffer is full When the log stream is starting a little while into the build, there might be a big burst of data sent through the socket which might fill it up. Then we need to be more patient and send the message again remembering what has been sent before. Signed-off-by: Michael Tremer --- src/pakfire/xfer.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/pakfire/xfer.c b/src/pakfire/xfer.c index fad3422a..569b4208 100644 --- a/src/pakfire/xfer.c +++ b/src/pakfire/xfer.c @@ -1639,16 +1639,33 @@ int pakfire_xfer_socket(struct pakfire_xfer* xfer, pakfire_xfer_open_callback op int pakfire_xfer_send_message(struct pakfire_xfer* xfer, const char* message, const size_t length) { size_t bytes_sent = 0; + size_t offset = 0; int r; // Send the message - r = curl_ws_send(xfer->handle, message, length, &bytes_sent, 0, CURLWS_TEXT); - if (r) { - ERROR(xfer->ctx, "Could not send message: %s\n", curl_easy_strerror(r)); + while (offset < length) { + r = curl_ws_send(xfer->handle, message + offset, length - offset, + &bytes_sent, 0, CURLWS_TEXT); - return r; + // Update offset + offset += bytes_sent; + + switch (r) { + // All done + case CURLE_OK: + goto DONE; + + // We could not send all data, try again + case CURLE_AGAIN: + continue; + + default: + ERROR(xfer->ctx, "Could not send message: %s\n", curl_easy_strerror(r)); + return r; + } } +DONE: // Log success DEBUG(xfer->ctx, "Successfully sent a WebSocket message of %zu byte(s)\n", bytes_sent); -- 2.39.5