thttpd挺好用的WEB服务器
可是遇到一个问题,当时间修改后,比如从1970年改到2013年时,thttpd就会占用CPU非常高。
查找后发现,其timers.c中tmr_run函数的实现有些问题,按如下修改后,问题解决:
void
tmr_run( struct timeval* nowP )
{
int h;
Timer* t;
Timer* next;
for ( h = 0; h < HASH_SIZE; ++h )
for ( t = timers[h]; t != (Timer*) 0; t = next )
{
next = t->next;
/* Since the lists are sorted, as soon as we find a timer
** that isn't ready yet, we can go on to the next list.
*/
if ( t->time.tv_sec > nowP->tv_sec ||
( t->time.tv_sec == nowP->tv_sec &&
t->time.tv_usec > nowP->tv_usec ) )
break;
(t->timer_proc)( t->client_data, nowP );
if ( t->periodic )
{
/* Reschedule. */
t->time.tv_sec += t->msecs / 1000L;
t->time.tv_usec += ( t->msecs % 1000L ) * 1000L;
if ( t->time.tv_usec >= 1000000L )
{
t->time.tv_sec += t->time.tv_usec / 1000000L;
t->time.tv_usec %= 1000000L;
}
//这里是添加的代码
if (t->time.tv_sec + 10*60 < nowP->tv_sec)
t->time.tv_sec = nowP->tv_sec;
//上面是添加的代码
l_resort( t );
}
else
tmr_cancel( t );
}
}
这其中,10*60是为了避免,作者可能确实希望程序能够在追赶当前时间的时候多运行几遍