mirror of
https://github.com/wangyu-/UDPspeeder.git
synced 2025-01-18 22:09:35 +08:00
fix clock goes backward, simpilify timer, hopefully it works
This commit is contained in:
parent
f0a7b28a63
commit
cacf0bcfcb
40
common.cpp
40
common.cpp
@ -495,25 +495,31 @@ u64_t get_current_time_us()
|
||||
return (uint64_t(tmp_time.tv_sec))*1000llu*1000llu+ (uint64_t(tmp_time.tv_nsec))/1000llu;
|
||||
}*/
|
||||
|
||||
u64_t get_current_time()//ms
|
||||
{
|
||||
//timespec tmp_time;
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
//return ((u64_t)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
||||
return (u64_t)(ev_time()*1000);
|
||||
}
|
||||
|
||||
u64_t get_current_time_rough()//ms
|
||||
{
|
||||
return (u64_t)(ev_now(ev_default_loop(0))*1000);
|
||||
}
|
||||
|
||||
u64_t get_current_time_us()
|
||||
{
|
||||
//timespec tmp_time;
|
||||
//clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
//return (uint64_t(tmp_time.tv_sec))*1000llu*1000llu+ (uint64_t(tmp_time.tv_nsec))/1000llu;
|
||||
return (u64_t)(ev_time()*1000*1000);
|
||||
static u64_t value_fix=0;
|
||||
static u64_t largest_value=0;
|
||||
|
||||
u64_t raw_value=(u64_t)(ev_time()*1000*1000);
|
||||
|
||||
u64_t fixed_value=raw_value+value_fix;
|
||||
|
||||
if(fixed_value< largest_value)
|
||||
{
|
||||
value_fix+= largest_value- fixed_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
largest_value=fixed_value;
|
||||
}
|
||||
|
||||
//printf("<%lld,%lld,%lld>\n",raw_value,value_fix,raw_value + value_fix);
|
||||
return raw_value + value_fix; //new fixed value
|
||||
}
|
||||
|
||||
u64_t get_current_time()
|
||||
{
|
||||
return get_current_time_us()/1000lu;
|
||||
}
|
||||
|
||||
u64_t pack_u64(u32_t a,u32_t b)
|
||||
|
2
common.h
2
common.h
@ -386,7 +386,7 @@ struct fd_info_t
|
||||
};
|
||||
|
||||
u64_t get_current_time();
|
||||
u64_t get_current_time_rough();
|
||||
//u64_t get_current_time_rough();
|
||||
u64_t get_current_time_us();
|
||||
u64_t pack_u64(u32_t a,u32_t b);
|
||||
|
||||
|
@ -116,14 +116,9 @@ int delay_manager_t::check()
|
||||
}
|
||||
if(!delay_mp.empty())
|
||||
{
|
||||
//itimerspec its;
|
||||
//memset(&its.it_interval,0,sizeof(its.it_interval));
|
||||
//its.it_value.tv_sec=delay_mp.begin()->first/1000000llu;
|
||||
//its.it_value.tv_nsec=(delay_mp.begin()->first%1000000llu)*1000llu;
|
||||
//timerfd_settime(timer_fd,TFD_TIMER_ABSTIME,&its,0);
|
||||
|
||||
const double m=1000*1000;
|
||||
ev_timer_stop(loop, &timer);
|
||||
ev_timer_set(&timer, delay_mp.begin()->first /1000000.0 - ev_now(loop),0 ); //we should use ev_now here.
|
||||
ev_timer_set(&timer, delay_mp.begin()->first/m -get_current_time_us()/m,0 );
|
||||
ev_timer_start(loop, &timer);
|
||||
}
|
||||
else
|
||||
|
@ -184,19 +184,11 @@ int fec_encode_manager_t::append(char *s,int len/*,int &is_first_packet*/)
|
||||
{
|
||||
if(counter==0)
|
||||
{
|
||||
my_itimerspec its;
|
||||
memset(&its.it_interval,0,sizeof(its.it_interval));
|
||||
first_packet_time=get_current_time_us();
|
||||
my_time_t tmp_time=fec_par.timeout+first_packet_time;
|
||||
its.it_value.tv_sec=tmp_time/1000000llu;
|
||||
its.it_value.tv_nsec=(tmp_time%1000000llu)*1000llu;
|
||||
//timerfd_settime(timer_fd,TFD_TIMER_ABSTIME,&its,0);
|
||||
|
||||
ev_timer_stop(loop, &timer);
|
||||
ev_timer_set(&timer, tmp_time/1000000.0 - ev_now(loop) ,0 ); //we should use ev_now here.
|
||||
ev_timer_set(&timer, fec_par.timeout/1000000.0 ,0 );
|
||||
ev_timer_start(loop, &timer);
|
||||
|
||||
//ev_timer_set(loop,)
|
||||
}
|
||||
if(fec_par.mode==0)//for type 0 use blob
|
||||
{
|
||||
|
@ -239,7 +239,7 @@ struct anti_replay_t
|
||||
}
|
||||
replay_buffer[index]=seq;
|
||||
assert(mp.find(seq)==mp.end());
|
||||
mp[seq].my_time=get_current_time_rough();
|
||||
mp[seq].my_time=get_current_time();
|
||||
mp[seq].index=index;
|
||||
index++;
|
||||
if(index==int(anti_replay_buff_size)) index=0;
|
||||
@ -248,7 +248,7 @@ struct anti_replay_t
|
||||
{
|
||||
if(mp.find(seq)==mp.end()) return 1;
|
||||
|
||||
if(get_current_time_rough()-mp[seq].my_time>anti_replay_timeout)
|
||||
if(get_current_time()-mp[seq].my_time>anti_replay_timeout)
|
||||
{
|
||||
replay_buffer[mp[seq].index]=u64_t(i64_t(-1));
|
||||
mp.erase(seq);
|
||||
|
Loading…
x
Reference in New Issue
Block a user