ev_timer problem

vvvua vvvua at faust.net.ua
Wed Jul 2 12:46:36 CEST 2008


Hello!
I'm trying to do a set of time watchers on default loop.
Default loop  also maintain an  async io on sockets. The program 
architecture  is designed with only one point of realisation of async 
calls - in ev_loop (loop,0) with default loop;
Socket i/o works fine, but i have a strange timer problem.
First, i create a timer at 45sec.
After each callback, i am trying to set timer on 5 seconds, but timer 
waits 45 seconds.
After some callback timer starts to wait 5 seconds...
Many time watchers can be active in same time.
Where is problem? Any ideas?
Thanks.

struct TimeSockMapper
{
    struct ev_timer tm;
    ev_tstamp repeat;
    int fd;
    void *defPoint;
    TimeSockMapper()
    {
        memset(&tm,0,sizeof(ev_timer));
        memset(&repeat,0,sizeof(ev_tstamp));
        fd=0;
        defPoint=NULL;
    }
};

void timeout_cb(EV_P_ struct ev_timer *w_, int revents)
{
    int cfd;
    struct TimeSockMapper * w= (struct TimeSockMapper *)w_;
    struct LocalOpcodeData * ldata = (struct LocalOpcodeData *) w->defPoint;
    cfd=w->fd;

    ev_timer_stop(loop,(ev_timer * )w);
...
}

void set_timeout(int fd, long long seconds,LocalOpcodeData *ldata)
{
    TimeSockMapper *mtm=new TimeSockMapper();
    mtm->repeat=0;
    mtm->fd=fd;
    mtm->defPoint=ldata;


    ev_timer_init (&(mtm-> tm), timeout_cb, seconds, 0.);
    ev_timer_set (&(mtm-> tm), seconds + ev_now (loop) - ev_time (), 0.);
    ev_timer_start (loop,&(mtm->tm));
}



More information about the libev mailing list