免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1761 | 回复: 7
打印 上一主题 下一主题

请问这段程序起什么作用的 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-10-29 11:49 |只看该作者 |倒序浏览
for( ; ; ) {
            if(sflg == 0) {            
                tv.tv_sec = WATCH_INTVL_START;//WATCH_INTVL_START=60
                tv.tv_usec = 0;
            }else{
                sflg = 0;                   /* flg:OFF */
                rest_time = tv.tv_sec +(tv.tv_usec/1000000);
                if(rest_time < 0 || rest_time > WATCH_INTVL_START) {
                    tv.tv_sec = WATCH_INTVL_START;
                    tv.tv_usec = 0;
                }
            }
          sret = select(0, NULL, NULL, NULL, &tv);
            if(sret < 0) {                  
                sflg = 1;                   /* flg:ON */
                printf("select err startup sync[errno:%d]\n", errno);
                continue;
            }

            sysinfo(&info);                 
            upminutes = (int) info.uptime / 60;

            if (upminutes >= startup_sync_time) {
                 
                log_sync_msgsnd();         
                break;                       
            }
        }
}

[ 本帖最后由 lusanchao 于 2007-10-29 12:07 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-10-29 11:53 |只看该作者
死循环

论坛徽章:
0
3 [报告]
发表于 2007-10-29 12:08 |只看该作者
我主要想问的是里面的时间函数 及select所起的作用  查了资料还是有些不明白

论坛徽章:
0
4 [报告]
发表于 2007-10-29 12:13 |只看该作者
你修改过的代码和你一开始贴出来的代码截然不同,拜托以后贴全了,你要问的代码不给出来。。。别人怎么看???
附上你刚才贴的代码

  1. for( ; ; ) {
  2.             if(sflg == 0) {            
  3.                 tv.tv_sec = WATCH_INTVL_START;//WATCH_INTVL_START=60
  4.                 tv.tv_usec = 0;
  5.             }else{
  6.                 sflg = 0;                   /* flg:OFF */
  7.                 rest_time = tv.tv_sec +(tv.tv_usec/1000000);
  8.                 if(rest_time < 0 || rest_time > WATCH_INTVL_START) {
  9.                     tv.tv_sec = WATCH_INTVL_START;
  10.                     tv.tv_usec = 0;
  11.                 }
  12.             }
  13. }
复制代码

论坛徽章:
0
5 [报告]
发表于 2007-10-29 12:17 |只看该作者
不好意思 刚才看了你的回答,觉得没说明白 就把主要的功能在贴出来 呵呵

论坛徽章:
0
6 [报告]
发表于 2007-10-29 12:18 |只看该作者
Some code calls select with all three sets empty, n zero, and a non-null timeout as a fairly portable way to sleep with subsecond precision.

On success, select and pselect return the number of descriptors contained in the descriptor sets, which may be zero if the timeout expires before  anything  interesting
       happens.  On error, -1 is returned, and errno is set appropriately; the sets and timeout become undefined, so do not rely on their contents after an error.

论坛徽章:
0
7 [报告]
发表于 2007-10-29 12:19 |只看该作者
select(0, NULL, NULL, NULL, &tv);这个函数是否是说过60秒后重新for循环

论坛徽章:
0
8 [报告]
发表于 2007-10-29 12:22 |只看该作者
在重进 for 循环之前会判断 if (upminutes >= startup_sync_time)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP