fcntl()函数,设置非阻塞 int flags = fcntl(fd, F_GETFL); flags |= O_NONBLOCK; //O_NONBLOCK: 0为阻塞,1为非阻塞 fcntl(fd, F_SETFL, flags);