ev_timer problem

vvvua vvvua at faust.net.ua
Thu Jul 3 17:26:15 CEST 2008


vvvua wrote:
> vvvua wrote:
>> vvvua wrote:
>>> Marc Lehmann wrote:
>>> > On Wed, Jul 02, 2008 at 01:46:36PM +0300, vvvua 
>>> <vvvua at faust.net.ua> wrote:
>>> >   >> 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;
>>> >>     >
>>> > It is totally unclear to me what you mean with "async io" - i 
>>> assume this
>>> > is something in your program?
>>> >   Yes. I mean input/output with sockets
>>>  ev_io_init (eh->getEvP(), func, sfd, flags);
>>>  ev_io_start (loop, eh->getEvP());
>>> >   >> First, i create a timer at 45sec.
>>> >> After each callback, i am trying to set timer on 5 seconds, but 
>>> timer  >> waits 45 seconds.
>>> >>     >
>>> > You should probbaly show the code for that.
>>> > Original code too big to show, but simple example is
>>> >   for(int i=100;i>0;i-=10)
>>> {
>>>   LocalOpcodeData *ldt = new LocalOpcodeData();
>>>   ldt->opcode=1;
>>>   set_timeout(fd, i,ldt);
>>> }
>>>   
>> Sorry, it was bad example. This example works fine, becouse time 
>> interval is still.
>>
>> Next example describes the problem:
>> */       / int a[3]={40,5,20};
>>        for(int i=0;i<3;i++)
>>        {
>>          LocalOpcodeData *ldt = new LocalOpcodeData();
>>          ldt->opcode=1;
>>          ldt->opcode_param0_uint=time(NULL);
>>          ldt->opcode_param1_int=a[i];
>>          cerr<<"\nsetTimeout="<<a[i]<<endl;
>>          set_timeout(cfd, i,ldt);
>>        }*
>>
>> And out is:
>> /setTimeout=40
>>
>> setTimeout=5
>>
>> setTimeout=20
>>
>> localOpcode=1
>> bot5 timer...5
>>
>> localOpcode=1
>> bot5 timer...20/
>>
>>
>> And the out of
>> /localOpcode=1
>> bot5 timer...5
>>
>> localOpcode=1
>> bot5 timer...20
>>
>> /happens at firs 1..3 seconds.
>> Timeout for 40 seconds not passed over a 2 minutes. And i do not wait 
>> for it any more.
> SORRY! I have  a bad day...
> set_timeout(cfd, i,ldt);
> must be
> set_timeout(cfd, a[i],ldt);
>
> After thet change works fine if i have a socket input/output.
> But...
> I setup first timer at 5 seconds.
> After callback i setup timers from last given example.
> If we have only timer activity callback function not called until i 
> have i/o on sockets.
> Waiting about of 1 minute..
> After socket i/o i have a call of callback function for all timers at 
> ones.
I made a local solution...
I created a heartbeat timer every 1 second at main thread. Now it works 
fine.
Is this problem has a different solution, if i do not want create a loop 
per thread?

>
>>
>>> >>    TimeSockMapper()
>>> >>    {
>>> >>        memset(&tm,0,sizeof(ev_timer));
>>> >>        memset(&repeat,0,sizeof(ev_tstamp));
>>> >>     >
>>> > You do not need to zero-initialise the watcher structures, this 
>>> will only
>>> > bloat your code.
>>> >   ok, i'll remove it.
>>> >   >> 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);
>>> >>     >
>>> > No restart here.
>>> >   it's ok
>>> >   >> 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));
>>> >>
>>> >>     >
>>> > No restart here either.
>>> >   that's also ok.
>>> > If the timer indeed doesn't restart as you want, then you should 
>>> show us
>>> > the code that actually resets the timer and restarts it - make 
>>> sure you
>>> > stop the timer before modifying it, or, even better, use 
>>> ev_timer_restart
>>> > and a suitable restart interval.
>>> >
>>> >   ev_loop is in different thread. Is this a problem?
>>>   
>>> ------------------------------------------------------------------------ 
>>>
>>>
>>> _______________________________________________
>>> libev mailing list
>>> libev at lists.schmorp.de
>>> http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> libev mailing list
>> libev at lists.schmorp.de
>> http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> libev mailing list
> libev at lists.schmorp.de
> http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20080703/8c1e0401/attachment.html>


More information about the libev mailing list