[代碼片段]linux設置套接口非阻塞特性

void set_noblocking(int sock)
{
    int opts = fcntl(sock, F_GETFL);
    if(opts < 0)
    {
        perror("fcntl(sock, F_GETFL)");
        exit(1);
    }
    opts = opts | O_NONBLOCK;
    if(fcntl(sock, F_SETFL, opts) < 0)
    {
        perror("fcntl(sock, F_SETFL, opts)");
        exit(1);
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章