不同类型文件“可读写”的含义

  • For sockets, readability means there is some unread data in the receivebuffer. That is well-known and probably the most common use case for non-blocking I/O. Conversely, writeability implies the send buffer is not full from the standpoint of the underlying protocol of the socket (e.g. TCP/IP). Ultimately, protocol-specific congestion control determines the exact mechanisms and policies for the send buffer.
  • For pipes, readability means some unread data remains in the pipe buffer, or one task is blocking in a write to the other end of the pipe. Reciprocally, writeability means the pipe buffer has available room, or one task is blocking in a read operation on the pipe.
  • FIFOs are really exactly like pipes, except that they have a name in the file system hierarchy.
  • Terminals and pseudo-terminals also work much like pipes, with regards to I/O, except for the fact that they support duplex operations like sockets.
  • For devices (other than terminals), polling is implementation-defined. You need to check the device driver documentation.
  • For directories, reading is only defined through blocking (synchronous) function calls, notably readdir() or readdir_r(). As such polling is not defined by the specifications and it would be of no use even if it were. Also writing to directories is not allowed at all.
  • Regular files are always readable and they are also always writeable. This is clearly stated in the relevant POSIX specifications. I cannot stress this enough. Putting a regular file in non-blocking has ABSOLUTELY no effectsother than changing one bit in the file flags.

Reading from a regular file might take a long time. For instance, if it is located on a busy disk, the I/O scheduler might take so much time that the user will notice that the application is frozen.

Nevertheless, non-blocking mode will not fix it. It will simply not work. Checking a file for readability or writeability always succeeds immediately. If the system needs time to perform the I/O operation, it will put the task in non-interruptible sleep from the read or write system call. In other words, if you can assume that a file descriptor refers to a regular file, do not waste your time (or worse, other people‘s time) in implementing non-blocking I/O.

The only safe way to read data from or write data to a regular file while not blocking a task... consists of not performing the operation - not in that particular task anyway. Concretely, you need to create a separate thread (or process), or use asynchronous I/O (functions whose name starts with aio_). Whether you like it or not, and even if you think multiple threads suck, there are no other options.

from (http://www.remlab.net/op/nonblock.shtml)

时间: 2024-10-11 07:06:05

不同类型文件“可读写”的含义的相关文章

nmon分析文件各sheet含义

sheet名称sheet含义 SYS_SUMM系统汇总,蓝线为cpu占有率变化情况,粉线为磁盘IO的变化情况: AAA关于操作系统以及nmon本身的一些信息: BBBB系统外挂存储容量以及存储类型: BBBC系统外挂存储位置.状态以及描述信息: BBBD磁盘适配器信息:(包含磁盘适配器名称以及描述) BBBE包含通过lsdev命令获取的系统设备及其特征,显示vpaths和hdisks之间的映射关系: BBBG显示磁盘组详细的映射关系: BBBL逻辑分区(LPAR)配置细节信息: BBBN网络适配

Linux文件权限符号含义

Linux文件权限符号含义在Linux中,每个文件都有不同的权限.用户可以使用ls -l命令查看权限属性.其中,符号含义如下所示:r:读权限.w:写权限.x:可执行权限.-:没有权限.s:SET位权限.t:粘滞位权限.例如,可执行文件ls的权限为-rwxr-xr-x.其中,第一个符号表示文件类型,-表示普通文件:后面分别为所有者权限.所属组的权限和其它用户权限.这里,表示ls文件的所有者权限为读.写和可执行:所属组的权限为读和可执行:其它用户权限为读和可执行.在一些文件权限属性后面,可能显示为点

Linux下find一次查找多个指定类型文件,指定文件或者排除某类文件

Linux下find一次查找多个指定文件或者排除某类文件,在 GREP 中匹配多个关键字的方法(1)Linux下find一次查找多个指定文件:查找a.html和b.html find . -name "a.html"  -name "b.html" find . -regex '.*\.txt\|.*\.doc\|.*\.mp3' find . -regex '.*\.txt\|.*\.doc\|.*\.mp3' ./a.txt ./a.doc ./a.mp3 (2

Linux下的C程序,遍历文件夹并统计其中各个类型文件所占百分比

递归遍历一个目录下的所有文件和文件夹,统计各个类型文件所占的百分比 程序代码a.cpp(编译命令:g++ a.cpp -o a) #include <stdio.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <dirent.h> #include <string.h> stru

如何在Qt资源文件中包含exe等各种类型文件?

操作系统:Windows 10 X64 企业版 Qt: 5.8.0 QtCreater: 4.2.1 刚刚开始学习Qt,不断遇到困难和挑战,前几天在各个QQ群里询问如何在Qt的资源文件中包含和释放exe可执行文件,结果没有谁给我一个准确的答复,包括问写过图书的选手!!我现在非常鄙视写书的选手,是高傲还是为了面子,对于我的问题根本就不回答!!!不仅仅是一个写书选手这样,很多个!!!我相信很多作者都是乐于帮助别人,极少数人才这个德性!!!! Qt做为开发了这么多年的跨平台GUI开发解决方案,我相信这

Ubuntu下用命令行快速打开各类型文件(转)

nautilus /media/pm/文档/book/system/必读nautilus /media/pm/文档/book/android/ndk 内核/framerwork/android waitReadxdg-open /media/pm/文档/book/system/必读/深入理解linux内核.pdf ubuntu 下一个神奇的命令--以窗口形式打开某个文件夹 今天意外的发现的一个命令 nautilus /media/ 会以窗口的形式打开某个目录,以后写脚本可以用到. Ubuntu下

Codeigniter 调试上传不支持的类型文件

打开 codeigniter\system\libraries\Upload.php 文件 找到执行方法 $this->_file_mime_type($_file); 注释后替换成 $this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die(); //abin add. 然后控制台查看输出的 mime类型是什么 再打开 codeigniter\application\config\mimes.php

asp.net word ecxel类型文件在线预览

首先得引用COM: Microsoft Excel 10 Object Library Microsoft Word 10 Object Library 或者是 10以上的类库 我现在用的是:资源下载: http://download.csdn.net/detail/panfuy/3247641 或者附件 Microsoft Excel 10 Object Library Microsoft Word 10 Object Library 代码如下: C#代码   using System; us

PHP header发送各种类型文件及设置文件下载名

PHP header发送各种类型文件及设置文件下载名 <?php header('Content-type: application/image/pjpeg');//输出的类型 header('Content-Disposition: attachment; filename="downloaded.jpg"'); //下载显示的名字,注意格式readfile('my.jpg');// 并将这个文件以前面header发送信息设定的类型输出,从而会弹出一个下载框// 就是把服务器上