@@ -194,6 +194,7 @@ struct hid_device_ {
194194 OVERLAPPED ol ;
195195 OVERLAPPED write_ol ;
196196 struct hid_device_info * device_info ;
197+ DWORD write_timeout_ms ;
197198};
198199
199200static hid_device * new_hid_device ()
@@ -219,6 +220,7 @@ static hid_device *new_hid_device()
219220 memset (& dev -> write_ol , 0 , sizeof (dev -> write_ol ));
220221 dev -> write_ol .hEvent = CreateEvent (NULL , FALSE, FALSE /*initial state f=nonsignaled*/ , NULL );
221222 dev -> device_info = NULL ;
223+ dev -> write_timeout_ms = 1000 ;
222224
223225 return dev ;
224226}
@@ -1052,6 +1054,11 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path)
10521054 return dev ;
10531055}
10541056
1057+ void HID_API_EXPORT_CALL hid_winapi_set_write_timeout (hid_device * dev , unsigned long timeout )
1058+ {
1059+ dev -> write_timeout_ms = timeout ;
1060+ }
1061+
10551062int HID_API_EXPORT HID_API_CALL hid_write (hid_device * dev , const unsigned char * data , size_t length )
10561063{
10571064 DWORD bytes_written = 0 ;
@@ -1103,7 +1110,7 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
11031110 if (overlapped ) {
11041111 /* Wait for the transaction to complete. This makes
11051112 hid_write() synchronous. */
1106- res = WaitForSingleObject (dev -> write_ol .hEvent , 1000 );
1113+ res = WaitForSingleObject (dev -> write_ol .hEvent , dev -> write_timeout_ms );
11071114 if (res != WAIT_OBJECT_0 ) {
11081115 /* There was a Timeout. */
11091116 register_winapi_error (dev , L"hid_write/WaitForSingleObject" );
0 commit comments