Update PipeReader.zig

This commit is contained in:
Jarred Sumner
2024-01-31 13:26:45 -08:00
parent 9574d92ba1
commit ff8a889b3d

View File

@@ -27,8 +27,10 @@ pub fn PosixPipeReader(
const buffer = @call(.always_inline, vtable.getBuffer, .{this});
const fd = @call(.always_inline, vtable.getFd, .{this});
if (comptime bun.Environment.isLinux) {
readFromBlockingPipeWithoutBlockingLinux(this, buffer, fd, 0);
return;
if (bun.C.linux.RWFFlagSupport.isMaybeSupported()) {
readFromBlockingPipeWithoutBlockingLinux(this, buffer, fd, 0);
return;
}
}
switch (bun.isReadable(fd)) {
@@ -61,11 +63,6 @@ pub fn PosixPipeReader(
}
}
const readFromBlockingPipeWithoutBlocking = if (bun.Environment.isLinux)
readFromBlockingPipeWithoutBlockingLinux
else
readFromBlockingPipeWithoutBlockingPOSIX;
// On Linux, we use preadv2 to read without blocking.
fn readFromBlockingPipeWithoutBlockingLinux(parent: *This, resizable_buffer: *std.ArrayList(u8), fd: bun.FileDescriptor, size_hint: isize) void {
if (size_hint > stack_buffer_len) {
@@ -120,6 +117,17 @@ pub fn PosixPipeReader(
}
}
fn readFromBlockingPipeWithoutBlocking(parent: *This, resizable_buffer: *std.ArrayList(u8), fd: bun.FileDescriptor, size_hint: isize) void {
if (comptime bun.Environment.isLinux) {
if (bun.C.linux.RWFFlagSupport.isMaybeSupported()) {
readFromBlockingPipeWithoutBlockingLinux(parent, resizable_buffer, fd, size_hint);
return;
}
}
readFromBlockingPipeWithoutBlockingPOSIX(parent, resizable_buffer, fd, size_hint);
}
fn readFromBlockingPipeWithoutBlockingPOSIX(parent: *This, resizable_buffer: *std.ArrayList(u8), fd: bun.FileDescriptor, size_hint: isize) void {
if (size_hint > stack_buffer_len) {
resizable_buffer.ensureUnusedCapacity(@intCast(size_hint)) catch bun.outOfMemory();