【Linux】 recv select非阻塞

void task_client_handle()
{
    fd_set fdset;
    
    while(1)
    {
        FD_SERO(&fdset);//clear fd_set
        FD_SET(sockfd,&fdset); //将sockfd添加到fset集合中

        struct timeval timeout = {5,0};//5妙超时时间
        int n = select(sockfd,&fdset,NULL.NULL,&timeout);
        if(n <= 0)
        {   //port_task_delay(1000);
            port_debug("select n <= 0,time out ,waiting....\n");
        }
        else
        {
            if(FD_ISSET(sockfd,&fdset))
            {
                port_take_mutex();
                int count = recvFromSer(client_buf,NETWORK_RECV_SIZE);
                port_give_mutex();

                if (count > 0)
                {
                    port_debug("recv count: %d  ", count);
                    channel_recv_data(client_buf, count);
                }
            }
        }
    }
}
发布了99 篇原创文章 · 获赞 80 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/zDavid_2018/article/details/104965746