Skip to content

Commit

Permalink
Windows: return bytes_written if WriteFile returns synchronously (#697)
Browse files Browse the repository at this point in the history
According to documentation, the system reserves the right to run
WriteFile synchronously, even if FILE_FLAG_OVERLAPPED is set,
so `bytes_written` needs to be taken from `WriteFile` directly in that case.
  • Loading branch information
Megamouse authored Sep 29, 2024
1 parent ba28d38 commit 5c4acf8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
length = dev->output_report_length;
}

res = WriteFile(dev->device_handle, buf, (DWORD) length, NULL, &dev->write_ol);
res = WriteFile(dev->device_handle, buf, (DWORD) length, &bytes_written, &dev->write_ol);

if (!res) {
if (GetLastError() != ERROR_IO_PENDING) {
Expand All @@ -1095,6 +1095,9 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
goto end_of_function;
}
overlapped = TRUE;
} else {
/* WriteFile() succeeded synchronously. */
function_result = bytes_written;
}

if (overlapped) {
Expand Down

0 comments on commit 5c4acf8

Please sign in to comment.