From ff8a889b3d3d86a5872def68c0181a2f10ca3b4f Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Wed, 31 Jan 2024 13:26:45 -0800 Subject: [PATCH] Update PipeReader.zig --- src/io/PipeReader.zig | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/io/PipeReader.zig b/src/io/PipeReader.zig index 572c68d36e..0749723676 100644 --- a/src/io/PipeReader.zig +++ b/src/io/PipeReader.zig @@ -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();