1、获取文件的flags,即open函数的第二个参数: flags = fcntl(fd,F_GETFL,0); 2、设置文件的flags: fcntl(fd,F_SETFL,flags); 3、增加文件的某个flags,比如文件是阻塞的,想设置成非阻塞: flags = fcntl(fd,F_GETFL,0); flags |= O_NONBLOCK; fcntl(fd,F_SETFL,flags); 4、取消文件的某个flags,比...
flags =fcntl(fd,F_GETFL,0); flags &= ~O_NONBLOCK;fcntl(fd,F_SETFL,flags); 获取和设置文件flags举例:: #include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<fcntl.h>#include<error.h>charbuf[500000];intmain(intargc,char*argv[]){intntowrite,nwrite;constchar*ptr ;intflags; nt...
但是fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFD, 0)|O_NONBLOCK)最后执行的结果应该是一样的,确实设为非阻塞了。所以很多人都认为正确的。唉。steven先生那本书写的很明明白白了。就没人仔细看吗。