[Kamailio-Devel] [SR-Dev] register_timer versus register_timer_process

Andrei Pelinescu-Onciul andrei at iptel.org
Tue Mar 10 23:05:03 CET 2009


On Mar 10, 2009 at 11:13, Ovidiu Sas <osas at voipembedded.com> wrote:
> Helo Andrei,
> 
> Can you point me to an example where fast timers are armed in
> sip-router, so I can try to update the ratelimit module.

#include "../../timer.h"
#include "../../timer_ticks.h"

/* simple periodic timer handler */
static ticks_t timer_h(ticks_t ticks, struct timer_ln* tl, void* data)
{
        DBG("timer habdler called at %d ticks, foo is %d \n", ticks, *(int*)data);
        return (ticks_t)(-1); /* periodical */
}

struct timer_ln *t;
int foo;

t=timer_alloc();
if (t==0)
        goto error;
timer_init(t, timer_handle, &foo, F_TIMER_FAST);
foo=0;
timer_add(t, MS_TO_TICKS(1500)); /* start it after 1500ms */
...


In the code you can find an example in modules/tm/timer.[ch] (but is
more complicated to follow since timer init and adding happen in
separate functions).
The timers are documented in doc/timers.txt (the above example is pasted
from there, the only difference being F_TIMER_FAST instead of 0 in
timer_init).


I've also added a fork_dummy_timer(...) function to sr, that is mostly
equivalent to what register_timer_process() does. The main difference
(besides params) is  that this function immediately forks the timer
process (as opposed to registering it), so you must call it from the 
modules child_init functions when the rank==PROC_MAIN (more details about 
when a process should be forked are in doc/modules_init.txt).
Note though that I haven't tested it.

I also don't have anything against if somebody implements a compatible
register_timer_process() (should be quite easy, one would only need to
keep a list and then call fork_dummy_timer() on each element), as long
as it would have a different name (since this would be not a "normal"
timer). I don't think it's needed, but if somebody really wants it...


Andrei
[...]



More information about the Devel mailing list