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 {
235235 });
236236 defer poller.deinit();
237237
238 while (!poller.done()) {
239 try poller.poll();
238 while (try poller.poll()) {
240239 if (poller.fifo(.stdout).count > max_output_bytes)
241240 return error.StdoutStreamTooLong;
242241 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 {
249249 self.* = undefined;
250250 }
251251
252 pub fn poll(self: *Self) !void {
252 pub fn poll(self: *Self) !bool {
253253 if (builtin.os.tag == .windows) {
254254 return pollWindows(self);
255255 } else {
......@@ -261,16 +261,7 @@ pub fn Poller(comptime StreamEnum: type) type {
261261 return &self.fifos[@enumToInt(which)];
262262 }
263263
264 pub fn done(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 {
264 fn pollWindows(self: *Self) !bool {
274265 const bump_amt = 512;
275266
276267 if (!self.windows.first_read_done) {
......@@ -295,7 +286,7 @@ pub fn Poller(comptime StreamEnum: type) type {
295286 }
296287
297288 while (true) {
298 if (self.windows.active.count == 0) return;
289 if (self.windows.active.count == 0) return false;
299290
300291 const status = os.windows.kernel32.WaitForMultipleObjects(
301292 self.windows.active.count,
......@@ -338,11 +329,11 @@ pub fn Poller(comptime StreamEnum: type) type {
338329 .pending => {},
339330 .closed => self.windows.active.removeAt(active_idx),
340331 }
341 return;
332 return true;
342333 }
343334 }
344335
345 fn pollPosix(self: *Self) !void {
336 fn pollPosix(self: *Self) !bool {
346337 // We ask for ensureUnusedCapacity with this much extra space. This
347338 // has more of an effect on small reads because once the reads
348339 // start to get larger the amount of space an ArrayList will
......@@ -352,8 +343,13 @@ pub fn Poller(comptime StreamEnum: type) type {
352343 const err_mask = os.POLL.ERR | os.POLL.NVAL | os.POLL.HUP;
353344
354345 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;
357353 inline for (&self.poll_fds, &self.fifos) |*poll_fd, *q| {
358354 // Try reading whatever is available before checking the error
359355 // conditions.
......@@ -366,12 +362,17 @@ pub fn Poller(comptime StreamEnum: type) type {
366362 if (amt == 0) {
367363 // Remove the fd when the EOF condition is met.
368364 poll_fd.fd = -1;
365 } else {
366 keep_polling = true;
369367 }
370368 } else if (poll_fd.revents & err_mask != 0) {
371369 // Exclude the fds that signaled an error.
372370 poll_fd.fd = -1;
371 } else if (poll_fd.fd != -1) {
372 keep_polling = true;
373373 }
374374 }
375 return keep_polling;
375376 }
376377 };
377378}