Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

nonblock

파일을 비봉쇄로 만든다.
int nonblock(int sockfd)
{
    int opts;
    opts = fcntl(sockfd, F_GETFL);
    if(opts < 0)
    {
        return -1;
    }
    opts = (opts | O_NONBLOCK);
    if(fcntl(sockfd, F_SETFL, opts) < 0)
    {
        return -1;
    }
    return 1;
}

다시 봉쇄로 할경우에는 O_NONBLOCK만 제거해 주면 된다.
int block(int sockfd)
{
    int opts;
    opts = fcntl(sockfd, F_GETFL);
    if(opts < 0)
    {
        return -1;
    }
    opts &= ~O_NONBLOCK;
    if(fcntl(sockfd, F_SETFL, opts) < 0)
    {
        return -1;
    }
    return 1;
}