Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timer-stop logic #18

Closed
M1cha opened this issue May 23, 2019 · 3 comments
Closed

timer-stop logic #18

M1cha opened this issue May 23, 2019 · 3 comments

Comments

@M1cha
Copy link

M1cha commented May 23, 2019

I was looking at these 4 lines:
https://github.com/troglobit/libuev/blob/a334d23/src/uev.c#L381

if (!w->u.t.period)
	w->u.t.timeout = 0;
if (!w->u.t.timeout)
	uev_timer_stop(w);

To me this looks like when there's no initial timeout, and only a periodic timer, the timer just gets stopped after the first expiration.
Is that a bug or intended behavior?

@troglobit
Copy link
Owner

That is intended behavior, not really well documented though. Setting timeout to zero disarms the timer. So for a periodic timer you have to set the initial delay as well.

The uev_timer_init() function calls uev_timer_set() (below):

libuev/src/timer.c

Lines 93 to 105 in a334d23

/**
* Reset a timer
* @param w Watcher to reset
* @param timeout Timeout in milliseconds before @param cb is called, zero disarms timer
* @param period For periodic timers this is the period time that @param timeout is reset to
*
* Note, the @param timeout value must be non-zero. Setting it to zero
* will disarm the timer. This is the underlying Linux function @func
* timerfd_settimer() which has this behavior.
*
* @return POSIX OK(0) or non-zero with @param errno set on error.
*/
int uev_timer_set(uev_t *w, int timeout, int period)

@M1cha
Copy link
Author

M1cha commented May 23, 2019

That part is not true though:

This is the underlying Linux function @func timerfd_settimer() which has this behavior. 

https://linux.die.net/man/2/timerfd_settime

Setting either field of new_value.it_value to a nonzero value arms the timer. Setting both fields of new_value.it_value to zero disarms the timer.

@M1cha
Copy link
Author

M1cha commented May 23, 2019

forget what I said. I didn't read properly and thought they were talking about "both" in the sense of "it_interval" and "it_value"

@M1cha M1cha closed this as completed May 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants