hidpp: move timeout checking before reading

When no report matches the report type or device, the previous code
did not terminate the loop early enough because the check was missed.
Now the timeout is always checked before attempting to poll.

Signed-off-by: Peter Wu <lekensteyn@gmail.com>
This commit is contained in:
Peter Wu 2013-08-28 18:21:45 +02:00 committed by Martin Pitt
parent 5058ede399
commit 789dbb037c

View file

@ -394,6 +394,16 @@ hidpp_device_read_resp (HidppDevice *device,
/* read from the device */
begin_time = g_get_monotonic_time () / 1000;
for (;;) {
/* avoid infinite loop when there is no response */
remaining_time = HIDPP_DEVICE_READ_RESPONSE_TIMEOUT -
(g_get_monotonic_time () / 1000 - begin_time);
if (remaining_time <= 0) {
g_set_error (error, 1, 0,
"timeout while reading response");
ret = FALSE;
goto out;
}
r = g_poll (poll, G_N_ELEMENTS(poll), remaining_time);
if (r < 0) {
if (errno == EINTR)
@ -453,16 +463,6 @@ hidpp_device_read_resp (HidppDevice *device,
goto out;
}
/* avoid infinite loop when there is no response */
remaining_time = HIDPP_DEVICE_READ_RESPONSE_TIMEOUT -
(g_get_monotonic_time () / 1000 - begin_time);
if (remaining_time <= 0) {
g_set_error (error, 1, 0,
"timeout while reading response");
ret = FALSE;
goto out;
}
/* not our message, ignore it and try again */
}