当nfds为0时,“select”会做什么?(What does “select” do when nfds is 0?)

编程入门 行业动态 更新时间:2024-10-26 06:38:54
当nfds为0时,“select”会做什么?(What does “select” do when nfds is 0?) int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

select , nfds的第一个参数应该是最大文件描述符加1,它应该至少为1。 但是我看到一些代码将nfds设置为0,这个用法是否合法? 另外,当nfds为负值或timeout值包含无效值时, select的返回值将设置为EINVAL 。 同样,它没有指定当nfds为0时发生了什么。

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

The first parameter of select, nfds, is supposed to be the maximum file descriptor plus 1, which should be at least 1. But I have seen some codes set nfds to be 0, is this usage legal? Plus, the return value of select is set to EINVAL when nfds is negative or timeout contains invalid value. Again, it does not specify what happened when nfds is 0.

最满意答案

可以使用select作为sleep的替代选择。 我相信它是通过将所有参数指定为0 / NULL来实现的,除了超时之外。 请教

为什么使用select()而不是sleep()?

It is possible to use select as an alternative for sleep. I believe it is achieved by specyfying all parameters as 0/NULL except timeout. Consult

Why use select() instead of sleep()?

更多推荐

本文发布于:2023-08-04 02:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1406738.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会做   nfds   select

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!