您的位置:首页 > 理论基础 > 计算机网络

[转] thttpd服务器在时间修改后导致CPU占用率过高的问题

2016-11-08 11:57 741 查看
转自:http://blog.csdn.net/taixinlfx/article/details/8727595

httpd挺好用的WEB服务器

可是遇到一个问题,当时间修改后,比如从1970年改到2013年时,thttpd就会占用CPU非常高。

查找后发现,其timers.c中tmr_run函数的实现有些问题,按如下修改后,问题解决:

[cpp] view
plain copy

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是为了避免,作者可能确实希望程序能够在追赶当前时间的时候多运行几遍
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: