| ... | ... | @@ -512,9 +512,17 @@ pub fn Poller(comptime StreamEnum: type) type { |
| 512 | 512 | |
| 513 | 513 | pub fn poll(self: *Self) !bool { |
| 514 | 514 | if (builtin.os.tag == .windows) { |
| 515 | | return pollWindows(self); |
| 515 | return pollWindows(self, null); |
| 516 | 516 | } else { |
| 517 | | return pollPosix(self); |
| 517 | return pollPosix(self, null); |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | pub fn pollTimeout(self: *Self, nanoseconds: u64) !bool { |
| 522 | if (builtin.os.tag == .windows) { |
| 523 | return pollWindows(self, nanoseconds); |
| 524 | } else { |
| 525 | return pollPosix(self, nanoseconds); |
| 518 | 526 | } |
| 519 | 527 | } |
| 520 | 528 | |
| ... | ... | @@ -522,7 +530,7 @@ pub fn Poller(comptime StreamEnum: type) type { |
| 522 | 530 | return &self.fifos[@intFromEnum(which)]; |
| 523 | 531 | } |
| 524 | 532 | |
| 525 | | fn pollWindows(self: *Self) !bool { |
| 533 | fn pollWindows(self: *Self, nanoseconds: ?u64) !bool { |
| 526 | 534 | const bump_amt = 512; |
| 527 | 535 | |
| 528 | 536 | if (!self.windows.first_read_done) { |
| ... | ... | @@ -553,10 +561,15 @@ pub fn Poller(comptime StreamEnum: type) type { |
| 553 | 561 | self.windows.active.count, |
| 554 | 562 | &self.windows.active.handles_buf, |
| 555 | 563 | 0, |
| 556 | | os.windows.INFINITE, |
| 564 | if (nanoseconds) |ns| |
| 565 | @min(std.math.cast(u32, ns / std.time.ns_per_ms) orelse (os.windows.INFINITE - 1), os.windows.INFINITE - 1) |
| 566 | else |
| 567 | os.windows.INFINITE, |
| 557 | 568 | ); |
| 558 | 569 | if (status == os.windows.WAIT_FAILED) |
| 559 | 570 | return os.windows.unexpectedError(os.windows.kernel32.GetLastError()); |
| 571 | if (status == os.windows.WAIT_TIMEOUT) |
| 572 | return true; |
| 560 | 573 | |
| 561 | 574 | if (status < os.windows.WAIT_OBJECT_0 or status > os.windows.WAIT_OBJECT_0 + enum_fields.len - 1) |
| 562 | 575 | unreachable; |
| ... | ... | @@ -594,7 +607,7 @@ pub fn Poller(comptime StreamEnum: type) type { |
| 594 | 607 | } |
| 595 | 608 | } |
| 596 | 609 | |
| 597 | | fn pollPosix(self: *Self) !bool { |
| 610 | fn pollPosix(self: *Self, nanoseconds: ?u64) !bool { |
| 598 | 611 | // We ask for ensureUnusedCapacity with this much extra space. This |
| 599 | 612 | // has more of an effect on small reads because once the reads |
| 600 | 613 | // start to get larger the amount of space an ArrayList will |
| ... | ... | @@ -603,7 +616,10 @@ pub fn Poller(comptime StreamEnum: type) type { |
| 603 | 616 | |
| 604 | 617 | const err_mask = os.POLL.ERR | os.POLL.NVAL | os.POLL.HUP; |
| 605 | 618 | |
| 606 | | const events_len = try os.poll(&self.poll_fds, std.math.maxInt(i32)); |
| 619 | const events_len = try os.poll(&self.poll_fds, if (nanoseconds) |ns| |
| 620 | std.math.cast(i32, ns / std.time.ns_per_ms) orelse std.math.maxInt(i32) |
| 621 | else |
| 622 | -1); |
| 607 | 623 | if (events_len == 0) { |
| 608 | 624 | for (self.poll_fds) |poll_fd| { |
| 609 | 625 | if (poll_fd.fd != -1) return true; |