ocean2811
6/12/2018 - 12:00 PM

Linux文件描述符设为非阻塞

Linux下 将文件描述符 设置为非阻塞状态

#include <unistd.h>
#include <fcntl.h>
void set()
{
  int fd;
  //...文件操作...
  
  int flags = fcntl(fd,F_GETFL);
  flags |= O_NONBLOCK;
  fcntl(fd,F_SETFL,flags);//设置文件描述符为非阻塞
}