文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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;
}
 
相关阅读 更多 +
排行榜 更多 +
终极街头格斗

终极街头格斗

休闲益智 下载
大炮轰飞机

大炮轰飞机

飞行射击 下载
像素打僵尸

像素打僵尸

飞行射击 下载