[英]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.