| ... | @@ -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 | } |
| 251 | | 251 | |
| 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 | } |
| 263 | | 263 | |
| 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; |
| 275 | | 266 | |
| 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 | } |
| 296 | | 287 | |
| 297 | while (true) { | 288 | while (true) { |
| 298 | if (self.windows.active.count == 0) return; | 289 | if (self.windows.active.count == 0) return false; |
| 299 | | 290 | |
| 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 | } |
| 344 | | 335 | |
| 345 | fn pollPosix(self: *Self) !void { | 336 | fn pollPosix(self: *Self) !bool { |
| 346 | // We ask for ensureUnusedCapacity with this much extra space. This | 337 | // We ask for ensureUnusedCapacity with this much extra space. This |
| 347 | // has more of an effect on small reads because once the reads | 338 | // has more of an effect on small reads because once the reads |
| 348 | // start to get larger the amount of space an ArrayList will | 339 | // 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; |
| 353 | | 344 | |
| 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 | } |
| 356 | | 351 | |
| | 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 error | 354 | // 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 | } |