]> git.ipfire.org Git - pakfire.git/commitdiff
xfer: Be patient when the websocket buffer is full
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2025 15:39:34 +0000 (15:39 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2025 15:39:34 +0000 (15:39 +0000)
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 <michael.tremer@ipfire.org>
src/pakfire/xfer.c

index fad3422ae5f5f30615616ae5354492e9bd1a2172..569b42087347eae7253e067270f7757f20e85808 100644 (file)
@@ -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);