[uart]linux串口的阻塞非阻塞切换

比如写的时候设置为阻塞,读的时候设置为非阻塞,就需要下面的切换方式

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);

如果fcntl(fd, F_SETFL, 0); 设置为阻塞状态

原文地址:https://www.cnblogs.com/aaronLinux/p/7798799.html