Skip to content

Commit 5c4acf8

Browse files
authored
Windows: return bytes_written if WriteFile returns synchronously (#697)
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.
1 parent ba28d38 commit 5c4acf8

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

windows/hid.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
10861086
length = dev->output_report_length;
10871087
}
10881088

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

10911091
if (!res) {
10921092
if (GetLastError() != ERROR_IO_PENDING) {
@@ -1095,6 +1095,9 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
10951095
goto end_of_function;
10961096
}
10971097
overlapped = TRUE;
1098+
} else {
1099+
/* WriteFile() succeeded synchronously. */
1100+
function_result = bytes_written;
10981101
}
10991102

11001103
if (overlapped) {

0 commit comments

Comments
 (0)