summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2022-07-18 21:04:46 +0200
committerLouis Burda <quent.burda@gmail.com>2023-06-23 00:35:52 +0200
commit905d33fff042b399e005c54dfda48690a9283850 (patch)
treeb9e04fd774e11d30cd2e7b797801ddd95be5519e
parent5fb2935eb5b953e3b8a56be301e13f581cadc546 (diff)
downloadwmsl-905d33fff042b399e005c54dfda48690a9283850.tar.gz
wmsl-905d33fff042b399e005c54dfda48690a9283850.zip
Move constant timeout to variable
-rw-r--r--wmsl.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/wmsl.c b/wmsl.c
index e57ba16..47ea5a6 100644
--- a/wmsl.c
+++ b/wmsl.c
@@ -154,6 +154,7 @@ run_block(const char *cmd, pid_t *pid)
bool
read_block(int fd, char *buf, ssize_t size)
{
+ const uint64_t timeout_ns = 1000000000;
struct timeval timeout;
struct timespec start, stop;
char tmp[256];
@@ -170,8 +171,8 @@ read_block(int fd, char *buf, ssize_t size)
FD_ZERO(&fdset);
FD_SET(fd, &fdset);
- timeout.tv_sec = 0;
- timeout.tv_usec = (1000000000 - ns) / 1000;
+ timeout.tv_sec = (timeout_ns - ns) / 1000000000;
+ timeout.tv_usec = (timeout_ns - ns) / 1000 % 1000000000;
ret = select(fd + 1, &fdset, NULL, NULL, &timeout);
@@ -196,7 +197,7 @@ read_block(int fd, char *buf, ssize_t size)
nread = read(fd, tmp, sizeof(tmp));
if (nread <= 0) break;
}
- } while (ns < 1000000000);
+ } while (ns < timeout_ns);
return tok != NULL;
}