-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
incremental(windows) add TransmitFile and some fixes for fetch, h2 an…
…d http (#8089) * fix win header decoding zig issue * fix libuv file read lifecycle * upload working without sendfile (yet) * undo * oops uncoment expect * add TransmitFile aka sendfile on windows * cleanup * [autofix.ci] apply automated fixes --------- Co-authored-by: cirospaciari <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Jarred Sumner <[email protected]>
- Loading branch information
1 parent
922ff08
commit 4611b84
Showing
10 changed files
with
107 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ const BoringSSL = @import("root").bun.BoringSSL; | |
const Arena = @import("../../mimalloc_arena.zig").Arena; | ||
const SendfileContext = struct { | ||
fd: bun.FileDescriptor, | ||
socket_fd: i32 = 0, | ||
socket_fd: bun.FileDescriptor = bun.invalid_fd, | ||
remain: Blob.SizeType = 0, | ||
offset: Blob.SizeType = 0, | ||
has_listener: bool = false, | ||
|
@@ -1277,8 +1277,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp | |
defer_deinit_until_callback_completes: ?*bool = null, | ||
|
||
// TODO: support builtin compression | ||
// TODO: Use TransmitFile on Windows | ||
const can_sendfile = !ssl_enabled and !bun.Environment.isWindows; | ||
const can_sendfile = !ssl_enabled; | ||
|
||
pub inline fn isAsync(this: *const RequestContext) bool { | ||
return this.defer_deinit_until_callback_completes == null; | ||
|
@@ -1894,6 +1893,14 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp | |
this.cleanupAndFinalizeAfterSendfile(); | ||
return errcode != .SUCCESS; | ||
} | ||
} else if(Environment.isWindows) { | ||
const win = std.os.windows; | ||
const uv = bun.windows.libuv; | ||
const socket = bun.socketcast(this.sendfile.socket_fd); | ||
const file_handle = uv.uv_get_osfhandle(bun.uvfdcast(this.sendfile.fd)); | ||
this.sendfile.offset += this.sendfile.remain; | ||
this.sendfile.remain = 0; | ||
return win.ws2_32.TransmitFile(socket, file_handle, 0, 0, null, null, 0) == 1; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cirospaciari
Author
Member
|
||
} else { | ||
var sbytes: std.os.off_t = adjusted_count; | ||
const signed_offset = @as(i64, @bitCast(@as(u64, this.sendfile.offset))); | ||
|
@@ -2066,7 +2073,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp | |
.remain = this.blob.Blob.offset + original_size, | ||
.offset = this.blob.Blob.offset, | ||
.auto_close = auto_close, | ||
.socket_fd = if (!this.flags.aborted) resp.getNativeHandle() else -999, | ||
.socket_fd = if (!this.flags.aborted) resp.getNativeHandle() else bun.invalid_fd, | ||
}; | ||
|
||
// if we are sending only part of a file, include the content-range header | ||
|
@@ -2158,7 +2165,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp | |
.remain = @as(Blob.SizeType, @truncate(result.result.buf.len)), | ||
.offset = if (this.blob == .Blob) this.blob.Blob.offset else 0, | ||
.auto_close = false, | ||
.socket_fd = -999, | ||
.socket_fd = bun.invalid_fd, | ||
}; | ||
|
||
this.response_buf_owned = .{ .items = result.result.buf, .capacity = result.result.buf.len }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@cirospaciari is this non-blocking?