文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>select 实例

select 实例

时间:2009-07-22  来源:sure_priterand

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char buf[100]="";
    struct timeval timeout;
    
    fd_set rset;
    FD_ZERO(&rset);
    FD_SET(0, &rset);
    FD_SET(2,&rset);
    FD_SET(4,&rset);

    while(1)   
    {
        timeout.tv_sec = 2;//设置超时时间为2秒
        timeout.tv_usec = 0;//设置超时时间0微秒
        if(select(1, &rset, NULL, NULL, &timeout)>0)
        {//如果在超时时间内(即 没超时)
            read(0, buf, 100);
            printf("buf=%s\n",buf);
        }
        else
            return 0;
    }
    return 0;
}
 
相关阅读 更多 +
排行榜 更多 +
卡车模拟器

卡车模拟器

模拟经营 下载
果缘购

果缘购

购物比价 下载
陆军运输飞船

陆军运输飞船

模拟经营 下载