authorgravatar for johnnymarler@gmail.comJonathan Marler <johnnymarler@gmail.com> 2023-02-28 21:00:10-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-03-01 12:21:53-05:00
logf2b15420ad595f77b6a3575dd7a6e85411dc69e9
tree714a157e82d7d9cfddfdede6be93306a30c2d141
parent138e8b162aeecc69cc62f0822e73b1862b7d07f6

std.io.poll: remove done function


2 files changed, 17 insertions(+), 17 deletions(-)

lib/std/child_process.zig+1-2
...@@ -235,8 +235,7 @@ pub const ChildProcess = struct {...@@ -235,8 +235,7 @@ pub const ChildProcess = struct {
235 });235 });
236 defer poller.deinit();236 defer poller.deinit();
237237
238 while (!poller.done()) {238 while (try poller.poll()) {
239 try poller.poll();
240 if (poller.fifo(.stdout).count > max_output_bytes)239 if (poller.fifo(.stdout).count > max_output_bytes)
241 return error.StdoutStreamTooLong;240 return error.StdoutStreamTooLong;
242 if (poller.fifo(.stderr).count > max_output_bytes)241 if (poller.fifo(.stderr).count > max_output_bytes)
lib/std/io.zig+16-15
...@@ -249,7 +249,7 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -249,7 +249,7 @@ pub fn Poller(comptime StreamEnum: type) type {
249 self.* = undefined;249 self.* = undefined;
250 }250 }
251251
252 pub fn poll(self: *Self) !void {252 pub fn poll(self: *Self) !bool {
253 if (builtin.os.tag == .windows) {253 if (builtin.os.tag == .windows) {
254 return pollWindows(self);254 return pollWindows(self);
255 } else {255 } else {
...@@ -261,16 +261,7 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -261,16 +261,7 @@ pub fn Poller(comptime StreamEnum: type) type {
261 return &self.fifos[@enumToInt(which)];261 return &self.fifos[@enumToInt(which)];
262 }262 }
263263
264 pub fn done(self: Self) bool {264 fn pollWindows(self: *Self) !bool {
265 if (builtin.os.tag == .windows)
266 return self.windows.first_read_done and self.windows.active.count == 0;
267
268 for (self.poll_fds) |poll_fd| {
269 if (poll_fd.fd != -1) return false;
270 } else return true;
271 }
272
273 fn pollWindows(self: *Self) !void {
274 const bump_amt = 512;265 const bump_amt = 512;
275266
276 if (!self.windows.first_read_done) {267 if (!self.windows.first_read_done) {
...@@ -295,7 +286,7 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -295,7 +286,7 @@ pub fn Poller(comptime StreamEnum: type) type {
295 }286 }
296287
297 while (true) {288 while (true) {
298 if (self.windows.active.count == 0) return;289 if (self.windows.active.count == 0) return false;
299290
300 const status = os.windows.kernel32.WaitForMultipleObjects(291 const status = os.windows.kernel32.WaitForMultipleObjects(
301 self.windows.active.count,292 self.windows.active.count,
...@@ -338,11 +329,11 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -338,11 +329,11 @@ pub fn Poller(comptime StreamEnum: type) type {
338 .pending => {},329 .pending => {},
339 .closed => self.windows.active.removeAt(active_idx),330 .closed => self.windows.active.removeAt(active_idx),
340 }331 }
341 return;332 return true;
342 }333 }
343 }334 }
344335
345 fn pollPosix(self: *Self) !void {336 fn pollPosix(self: *Self) !bool {
346 // We ask for ensureUnusedCapacity with this much extra space. This337 // We ask for ensureUnusedCapacity with this much extra space. This
347 // has more of an effect on small reads because once the reads338 // has more of an effect on small reads because once the reads
348 // start to get larger the amount of space an ArrayList will339 // start to get larger the amount of space an ArrayList will
...@@ -352,8 +343,13 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -352,8 +343,13 @@ pub fn Poller(comptime StreamEnum: type) type {
352 const err_mask = os.POLL.ERR | os.POLL.NVAL | os.POLL.HUP;343 const err_mask = os.POLL.ERR | os.POLL.NVAL | os.POLL.HUP;
353344
354 const events_len = try os.poll(&self.poll_fds, std.math.maxInt(i32));345 const events_len = try os.poll(&self.poll_fds, std.math.maxInt(i32));
355 if (events_len == 0) return;346 if (events_len == 0) {
347 for (self.poll_fds) |poll_fd| {
348 if (poll_fd.fd != -1) return true;
349 } else return false;
350 }
356351
352 var keep_polling = false;
357 inline for (&self.poll_fds, &self.fifos) |*poll_fd, *q| {353 inline for (&self.poll_fds, &self.fifos) |*poll_fd, *q| {
358 // Try reading whatever is available before checking the error354 // Try reading whatever is available before checking the error
359 // conditions.355 // conditions.
...@@ -366,12 +362,17 @@ pub fn Poller(comptime StreamEnum: type) type {...@@ -366,12 +362,17 @@ pub fn Poller(comptime StreamEnum: type) type {
366 if (amt == 0) {362 if (amt == 0) {
367 // Remove the fd when the EOF condition is met.363 // Remove the fd when the EOF condition is met.
368 poll_fd.fd = -1;364 poll_fd.fd = -1;
365 } else {
366 keep_polling = true;
369 }367 }
370 } else if (poll_fd.revents & err_mask != 0) {368 } else if (poll_fd.revents & err_mask != 0) {
371 // Exclude the fds that signaled an error.369 // Exclude the fds that signaled an error.
372 poll_fd.fd = -1;370 poll_fd.fd = -1;
371 } else if (poll_fd.fd != -1) {
372 keep_polling = true;
373 }373 }
374 }374 }
375 return keep_polling;
375 }376 }
376 };377 };
377}378}