简体   繁体   English

select() 如何返回除 -1、0 或 1 之外的任何值?

[英]How would select() return anything other than -1, 0, or 1?

This is definitely just a dumb misunderstanding on my part, but the man page for select() states:这对我来说绝对只是一个愚蠢的误解,但是 select() 的手册页指出:

The timeout argument specifies the interval that select() should block waiting for a file descriptor to become ready. timeout 参数指定 select() 应阻止等待文件描述符准备就绪的时间间隔。 The call will block until either:调用将阻塞,直到:

*a file descriptor becomes ready; *文件描述符准备就绪;

*the call is interrupted by a signal handler; *调用被信号处理程序中断; or或者

*the timeout expires. *超时到期。

And furthermore, that而且,那

On success, select() and pselect() return the number of file descriptors contained in the three returned descriptor sets (that is, the total number of bits that are set in readfds, writefds, exceptfds) which may be zero if the timeout expires before anything interesting happens.成功时,select() 和 pselect() 返回三个返回的描述符集中包含的文件描述符的数量(即在 readfds、writefds、exceptfds 中设置的总位数),如果超时到期可能为零在任何有趣的事情发生之前。 On error, -1 is returned, and errno is set to indicate the error;出错时返回-1,设置errno表示出错; the file descriptor sets are unmodified, and timeout becomes undefined.文件描述符集未修改,超时未定义。

So my question is -- if it stops blocking as soon as a file descriptor is ready, would it not immediately return 1?所以我的问题是——如果它在文件描述符准备好后立即停止阻塞,它会不会立即返回 1? And if no fds become ready, it returns 0, otherwise error and returns -1.如果没有 fds 准备好,则返回 0,否则返回错误并返回 -1。

Obviously in practice it returns more than 1: the whole point is that you should be able to read/write multiple fds, right?显然在实践中它返回超过 1:重点是你应该能够读/写多个 fds,对吧?

由于现代抢占式多任务的工作方式,多个描述符可能会在您的进程被唤醒之前准备就绪,并且select调用对描述符进行计数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 _sync_val_compare_and_swap是否可以返回int以外的任何东西? - can _sync_val_compare_and_swap return anything other than int? stdout除了控制台窗口之外还有什么吗? - Is stdout Ever Anything Other Than a Console Window? ncurses程序崩溃除了PuTTY以外的任何东西 - ncurses program crashes on anything other than PuTTY 无法弄清楚如何使用if语句返回除选项之外的其他任何内容 - can't figure out how to use if statements to return anything other then one option -Ofast以外的任何其他东西都会导致“未定义的引用”错误 - Anything other than -Ofast causes “undefined reference” error 泰勒级数的此代码不适用于n = 1或0以外的任何其他值。为什么? - This code of taylor series doesn't work for n= 1 or anything other than 0. Why? 猜数字问题。 当输入除整数以外的任何内容时,程序会显示意外行为 - Guess the number problem. When anything other than integers is entered program shows unexpected behaviour 当我尝试索引除零以外的任何内容时,指向越界索引的结构指针(?) - Pointer to pointer of structs indexing out of bounds(?) when I try to index anything other than zero 不返回任何内容的程序 - Program that does not return anything 除了创建一个线程以外,另一个访问线程的返回值 - Accessing to return value of a thread by another one other than creating one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM