Compare commits

...

2 Commits

Author SHA1 Message Date
Jarred Sumner
ed1a70c433 Update PipeReader.zig 2025-06-01 00:11:11 -07:00
Jarred Sumner
535fef265f Remove the usage of poll on macOS because it lies 2025-06-01 00:10:21 -07:00

View File

@@ -432,12 +432,10 @@ const PosixBufferedReader = struct {
return readWithFn(parent, resizable_buffer, fd, size_hint, received_hup, .pipe, wrapReadFn(bun.sys.readNonblocking));
}
fn readWithFn(parent: *PosixBufferedReader, resizable_buffer: *std.ArrayList(u8), fd: bun.FileDescriptor, size_hint: isize, received_hup_: bool, comptime file_type: FileType, comptime sys_fn: *const fn (bun.FileDescriptor, []u8, usize) JSC.Maybe(usize)) void {
fn readWithFn(parent: *PosixBufferedReader, resizable_buffer: *std.ArrayList(u8), fd: bun.FileDescriptor, size_hint: isize, received_hup: bool, comptime file_type: FileType, comptime sys_fn: *const fn (bun.FileDescriptor, []u8, usize) JSC.Maybe(usize)) void {
_ = size_hint; // autofix
const streaming = parent.vtable.isStreamingEnabled();
var received_hup = received_hup_;
if (streaming) {
const stack_buffer = parent.vtable.eventLoop().pipeReadBuffer();
while (resizable_buffer.capacity == 0) {
@@ -467,39 +465,19 @@ const PosixBufferedReader = struct {
if (comptime file_type == .pipe) {
if (bun.Environment.isMac or !bun.linux.RWFFlagSupport.isMaybeSupported()) {
switch (bun.isReadable(fd)) {
.ready => {},
.hup => {
received_hup = true;
},
.not_ready => {
if (received_hup) {
parent.closeWithoutReporting();
}
defer {
if (received_hup) {
parent.done();
}
}
if (stack_buffer[0 .. stack_buffer.len - stack_buffer_head.len].len > 0) {
if (!parent.vtable.onReadChunk(stack_buffer[0 .. stack_buffer.len - stack_buffer_head.len], if (received_hup) .eof else .drained)) {
return;
}
}
if (!received_hup) {
parent.registerPoll();
}
if (stack_buffer[0 .. stack_buffer.len - stack_buffer_head.len].len > 0) {
if (!parent.vtable.onReadChunk(stack_buffer[0 .. stack_buffer.len - stack_buffer_head.len], if (received_hup) .eof else .drained)) {
return;
},
}
}
}
}
if (comptime file_type != .pipe) {
// blocking pipes block a process, so we have to keep reading as much as we can
// otherwise, we do want to stream the data
if (!received_hup) {
parent.registerPoll();
}
return;
}
} else {
if (stack_buffer_head.len < stack_buffer_cutoff) {
if (!parent.vtable.onReadChunk(stack_buffer[0 .. stack_buffer.len - stack_buffer_head.len], if (received_hup) .eof else .progress)) {
return;
@@ -561,28 +539,20 @@ const PosixBufferedReader = struct {
if (comptime file_type == .pipe) {
if (bun.Environment.isMac or !bun.linux.RWFFlagSupport.isMaybeSupported()) {
switch (bun.isReadable(fd)) {
.ready => {},
.hup => {
received_hup = true;
},
.not_ready => {
if (received_hup) {
parent.closeWithoutReporting();
}
defer {
if (received_hup) {
parent.done();
}
}
if (!received_hup) {
parent.registerPoll();
}
return;
},
if (received_hup) {
parent.closeWithoutReporting();
}
defer {
if (received_hup) {
parent.done();
}
}
if (!received_hup) {
parent.registerPoll();
}
return;
}
}
},
@@ -623,41 +593,20 @@ const PosixBufferedReader = struct {
if (comptime file_type == .pipe) {
if (bun.Environment.isMac or !bun.linux.RWFFlagSupport.isMaybeSupported()) {
switch (bun.isReadable(fd)) {
.ready => {},
.hup => {
received_hup = true;
},
.not_ready => {
if (received_hup) {
parent.closeWithoutReporting();
}
defer {
if (received_hup) {
parent.done();
}
}
if (parent.vtable.isStreamingEnabled()) {
defer {
resizable_buffer.clearRetainingCapacity();
}
if (!parent.vtable.onReadChunk(resizable_buffer.items, if (received_hup) .eof else .drained) and !received_hup) {
return;
}
}
if (!received_hup) {
parent.registerPoll();
}
if (parent.vtable.isStreamingEnabled()) {
defer {
resizable_buffer.clearRetainingCapacity();
}
if (!parent.vtable.onReadChunk(resizable_buffer.items, if (received_hup) .eof else .drained) and !received_hup) {
return;
},
}
}
}
}
if (comptime file_type != .pipe) {
parent.registerPoll();
return;
}
} else {
if (parent.vtable.isStreamingEnabled()) {
if (resizable_buffer.items.len > 128_000) {
defer {