| 46 | } |
| 47 | |
| 48 | void reset_timer(int fd, int old_timer, int new_timer) { |
| 49 | if (old_timer <= 0) { |
| 50 | /* We had a paused fd; resume it */ |
| 51 | set_timeout(new_timer, 0, fd, 0); |
| 52 | } else { |
| 53 | time_t fd_timeout = get_timeout_sec(fd); |
| 54 | if (fd_timeout == 0 && new_timer > 0) { |
| 55 | /* |
| 56 | * fd was ready to fire; we are not pausing it |
| 57 | * thus we can safely let it fire. |
| 58 | * Note: this happens after eg: a long night suspend |
| 59 | */ |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | unsigned int elapsed_time = old_timer - fd_timeout; |
| 64 | /* if we still need to wait some seconds */ |
| 65 | if (new_timer > elapsed_time) { |
| 66 | set_timeout(new_timer - elapsed_time, 0, fd, 0); |
| 67 | } else if (new_timer > 0) { |
| 68 | /* with new timeout, old_timeout would already have elapsed */ |
| 69 | set_timeout(0, 1, fd, 0); |
| 70 | } else { |
| 71 | /* pause fd as a timeout <= 0 has been set */ |
| 72 | set_timeout(0, 0, fd, 0); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void read_timer(int fd) { |
| 78 | uint64_t t; |
no test coverage detected