Typcical code to enable nonblocking I/O

The following is the code coming from Uinx Network Programming on page 235:

int flags;

        /* set a socket as nonblocking */
if( (flags = fcntl(fd, F_GETFL, 0)) < 0)
        err_sys("F_GETFL error");
flags |= O_NONBLOCK;        /* This is very inportant or you will clear all other status flags about this file */
if(fcntl(fd, F_SETFL, flags) < 0)
        err_sys("F_SETFL error");

turn off the nonblocking:

flags &= ~O_NONBLOCK;
if(fcntl(fd, F_SETFL, flags) < 0)
        err_sys("F_SETFL error");
原文地址:https://www.cnblogs.com/wangshuo/p/2022025.html