commit 35602793a52e494da3b52f3c4167467fb24a877b
parent 99702eb036df0ebe9e83ef4f91f8e84f0b9fb0d8
Author: amin <dev@aminmesbah.com>
Date: Sun, 29 May 2022 05:40:11 +0000
Fix select() timeout after hibernate
`select()` was timing out unceasingly after resume from system
hibernation. Setting the fd_set right before calling `select()` fixes
that.
FossilOrigin-Name: c6a2ab9a81f482f3cc40438d93595e90015f0b08a6ed28df8600a1a7a37f18ae
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/main.c b/main.c
@@ -53,7 +53,6 @@ int main(void)
bool error_occurred = false;
int device_handle = -1;
bool need_send_feature_report = true;
- fd_set read_fds;
while (running)
{
@@ -80,8 +79,6 @@ int main(void)
goto error;
}
- FD_ZERO(&read_fds);
- FD_SET(device_handle, &read_fds);
need_send_feature_report = true;
}
@@ -96,6 +93,9 @@ int main(void)
need_send_feature_report = false;
}
+ fd_set read_fds;
+ FD_ZERO(&read_fds);
+ FD_SET(device_handle, &read_fds);
errno = 0;
int ready = select(device_handle + 1, &read_fds, NULL, NULL, &(struct timeval){ .tv_sec = 15 });
if (ready == -1 && errno != EINTR)