Skip to content

Commit 787a46d

Browse files
Write more data faster (#23989)
### What does this PR do? ### How did you verify your code works?
1 parent 29028bb commit 787a46d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/http.zig

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,19 @@ pub fn flushStream(this: *HTTPClient, comptime is_ssl: bool, socket: NewHTTPCont
10081008

10091009
/// Write data to the socket (Just a error wrapper to easly handle amount written and error handling)
10101010
fn writeToSocket(comptime is_ssl: bool, socket: NewHTTPContext(is_ssl).HTTPSocket, data: []const u8) !usize {
1011-
const amount = socket.write(data);
1012-
if (amount < 0) {
1013-
return error.WriteFailed;
1011+
var remaining = data;
1012+
var total_written: usize = 0;
1013+
while (remaining.len > 0) {
1014+
const amount = socket.write(remaining);
1015+
if (amount < 0) {
1016+
return error.WriteFailed;
1017+
}
1018+
const wrote: usize = @intCast(amount);
1019+
total_written += wrote;
1020+
remaining = remaining[wrote..];
1021+
if (wrote == 0) break;
10141022
}
1015-
return @intCast(amount);
1023+
return total_written;
10161024
}
10171025

10181026
/// Write data to the socket and buffer the unwritten data if there is backpressure

0 commit comments

Comments
 (0)