diff options
| author | Louis Burda <quent.burda@gmail.com> | 2022-07-18 21:04:46 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-06-23 00:35:52 +0200 |
| commit | 905d33fff042b399e005c54dfda48690a9283850 (patch) | |
| tree | b9e04fd774e11d30cd2e7b797801ddd95be5519e | |
| parent | 5fb2935eb5b953e3b8a56be301e13f581cadc546 (diff) | |
| download | wmsl-905d33fff042b399e005c54dfda48690a9283850.tar.gz wmsl-905d33fff042b399e005c54dfda48690a9283850.zip | |
Move constant timeout to variable
| -rw-r--r-- | wmsl.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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; } |
