aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2024-09-29 00:03:46 +0100
committermlugg <mlugg@mlugg.co.uk>2024-10-06 07:01:12 +0100
commit90db7677212f8331733a661615490d37c7bf75d2 (patch)
treee208936079ab24bcc0583820369c28c6ce8a3a59 /lib/std/debug.zig
parentada60616b37b76004237f4e13de8b552c16dc773 (diff)
downloadzig-90db7677212f8331733a661615490d37c7bf75d2.tar.gz
zig-90db7677212f8331733a661615490d37c7bf75d2.zip
std: async read into small temporary buffer between `poll` calls on Windows
This commit changes how `std.io.poll` is implemented on Windows. The new implementation unfortunately incurs a little extra system call overhead, but fixes several bugs in the old implementation: * The `lpNumberOfBytesRead` parameter of `ReadFile` was used with overlapped I/O. This is explicitly disallowed by the documentation, as the value written to this pointer is "potentially erroneous"; instead, `GetOverlappedResult` must always be used, even if the operation immediately returns. Documentation states that `lpNumberOfBytesRead` cannot be passed as null on Windows 7, so for compatibility, the parameter is passed as a pointer to a dummy global. * If the initial `ReadFile` returned data, and the next read returned `BROKEN_PIPE`, the received data was silently ignored in the sense that `pollWindows` did not `return`, instead waiting for data to come in on another file (or for all files to close). * The asynchronous `ReadFile` calls which were left pending between calls to `pollWindows` pointed to a potentially unstable buffer, since the user of `poll` may use part of the `LinearFifo` API which rotate its ring buffer. This race condition was causing CI failures in some uses of the compiler server protocol. These issues are all resolved. Now, `pollWindows` will queue an initial read to a small (128-byte) stable buffer per file. When this read is completed, reads directly into the FIFO's writable slice are performed until one is left pending, at which point that read is cancelled (with a check to see if it was completed between the `ReadFile` and `CancelIo` calls) and the next read into the small stable buffer is queued. These small buffer reads are the ones left pending between `pollWindows` calls, avoiding the race condition described above. Related: #21565
Diffstat (limited to 'lib/std/debug.zig')
0 files changed, 0 insertions, 0 deletions