1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-26 08:20:27 +00:00

windows: fix ev/read hang when called on fs stream

handles returned by CreateFileA and FILE_FLAG_OVERLAPPED
support reading from arbitrary offsets.
The offset is passed to ReadFile in through the OVERLAPPED structure.
Since state->overlapped is zeroed ev_machine_read
ReadFile would always read from the start of the file and never finish

This commit changes ev_machine_read to update the offset to
the number of bytes read before calling ReadFile.
This commit is contained in:
Ian Shehadeh 2022-01-07 16:32:39 -05:00
parent 07ec89276b
commit 60378ff941

View File

@ -2219,6 +2219,10 @@ JanetAsyncStatus ev_machine_read(JanetListenerState *s, JanetAsyncEvent event) {
} else
#endif
{
// Some handles (not all) read from the offset in lopOverlapped
// if its not set before calling `ReadFile` these streams will always read from offset 0
state->overlapped.Offset = (DWORD) state->bytes_read;
status = ReadFile(s->stream->handle, state->chunk_buf, chunk_size, NULL, &state->overlapped);
if (!status && (ERROR_IO_PENDING != WSAGetLastError())) {
if (WSAGetLastError() == ERROR_BROKEN_PIPE) {