*nix select 和exceptfds/errorfds 语义 [英] *nix select and exceptfds/errorfds semantics

查看:40
本文介绍了*nix select 和exceptfds/errorfds 语义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

select 系统调用需要 3 个文件描述符集来观看 fds 以确保可读性/writeable 和文件描述符上的异常".

The select syscall takes 3 filedescriptor sets for watching fds for readable/writeable and "exceptions" on filedescriptor.

我的选择 manpage 没有过多说明 exceptfd 描述符集.这有什么用途;什么样的异常可以并且会通知文件描述符?

My select man page doesn't state much about the exceptfd descriptor set. What is it used for; what kind of exceptions can and will it notify on file descriptors?

我假设这对于描述符类型可能会有所不同......无论是 TCP 套接字、管道、tty 等).有没有人有关于 select 可以报告不同类型的描述符的哪些类型的错误的更多信息?

I'm assuming this can be different for the descriptor type... whether it's a TCP socket, a pipe, a tty , etc.). Does anyone have more info on what kind of errors select can report on the different kinds of descriptors?

推荐答案

有时认为需要 exceptfds 来检测错误,但这是一种误解.错误将在 readfds 中标记.尽管 POSIX 需要它(甚至调用参数 errorfds),它取决于操作系统是否也在 exceptfds 中标记错误.确实,只有在您关心异常情况时才需要此参数,但很少需要检测这些情况.

It is sometimes thought that exceptfds is needed to detect errors, but that is a misconception. Errors will be flagged in readfds. Although POSIX requires it (and even calls the parameter errorfds), it depends on the OS whether errors are also flagged in exceptfds. Really, this parameter is only needed if you care about exceptional conditions, but only rarely is there any need to detect those.

什么是异常条件取决于文件描述符的类型,但到目前为止最常见的用途是在 TCP 套接字上,它表明可以使用 recv() 带有 MSG_OOB 标志.然而,TCP 带外数据有许多怪癖(例如,只有 1 个字节可以是未完成的),因此很少使用.

What qualifies as an exceptional condition depends on the kind of file descriptor, but by far the most common use is on a TCP socket where it indicates that out-of-band data is available to be read using recv() with the MSG_OOB flag. However, TCP out-of-band data has a number of quirks (e.g. only 1 byte can be outstanding) and as a result is rarely used.

在最近的 Linux 内核中,exceptfds 可用于检测某些 sysfs 属性何时发生变化.属性的当前值可以通过读取/sys下的相应文件来读取,文件描述符上的一个select()会标记exceptfds 当属性改变时.但是,这目前仅适用于某些属性和挂载更改 (/proc/mounts).

In recent Linux kernels exceptfds can be used to detect when certain sysfs attributes change. The current value of the attribute can be read by reading the appropriate file under /sys, and a select() on the file descriptor will flag exceptfds when the attribute changes. However this currently only works for some of the attributes, and for mount changes (/proc/mounts).

还有一些设备驱动程序会使用 exceptfds 标记某些特定于设备的条件.

Also some device drivers will flag certain device-specific conditions using exceptfds.

这篇关于*nix select 和exceptfds/errorfds 语义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆