Server Help

ASSS Questions - ml->SetTimer()

Mr Ekted - Fri Mar 10, 2006 3:25 pm
Post subject: ml->SetTimer()
The design of this interface...

Code: Show/Hide
void (*SetTimer)(TimerFunc func, int initialdelay, int interval, void *param, void *key);


assumes that the CALLED function wants control of repetition. The return value is used to indicate what to do. In general, I have found that the CALLING function knows more about what it wants. Therefore I propose the following change:

If the interval is set to 0 (zero), then the timer only triggers once. This only requires a change of one line of code in mainloop.c:

Code: Show/Hide
from:

if (td->killme || !ret)

to:

if (td->killme || !td->interval || !ret)


I suppose this could conflict with those who expect a 0 (zero) interval to repeat as fast as the main loop is able. In that case, it would be possible to define something like:

Code: Show/Hide
#define NOREPEAT -1


and use it as an interval value.
Dr Brain - Fri Mar 10, 2006 7:04 pm
Post subject:
I agree that it's a little strange, but I've never had a big problem with it. That's mostly because thus far my timer functions have been very closely tied to the calling function, meaning it doesn't matter who controls the rescheduling.
Grelminar - Tue Mar 14, 2006 2:42 am
Post subject:
I've also never wanted this functionality. Generally the calling and called functions are very closely coupled. But since it only adds functionality and doesn't break anything existing, I'll add it.

If you want to be called for each main loop iteration, register a CB_MAINLOOP callback, don't use a timer.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group