MCPcopy Create free account
hub / github.com/FedeDP/Clight / reset_timer

Function reset_timer

src/utils/timer.c:48–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48void 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
77void read_timer(int fd) {
78 uint64_t t;

Callers 2

timeout_callbackFunction · 0.85
reset_or_pauseFunction · 0.85

Calls 2

set_timeoutFunction · 0.85
get_timeout_secFunction · 0.85

Tested by

no test coverage detected