[英]get file descriptor at x from fd_set c++ linux
I know on windows you can get a file descriptor by doing myfd_set.fd_array[x] but when I try and do that on Linux it does not work.我知道在 Windows 上您可以通过执行 myfd_set.fd_array[x] 来获取文件描述符,但是当我尝试在 Linux 上执行此操作时,它不起作用。 What do I have to do to get a file descriptor?我该怎么做才能获得文件描述符?
There's no macro defined by POSIX to do what you're asking. POSIX 没有定义宏来执行您的要求。
The technique you've used on Windows is viable because the structure of a descriptor set is documented on that platform, so you have reliable access to its innards.您在 Windows 上使用的技术是可行的,因为描述符集的结构记录在该平台上,因此您可以可靠地访问其内部结构。
Generally, you wouldn't need this functionality.通常,您不需要此功能。 I don't think I've ever seen a poll loop that needed to obtain the n th descriptor in an FD_SET
.我认为我从未见过需要在FD_SET
获取第n个描述符的轮询循环。 Usually, you add your FDs to a set, pass it to select
, then — looping back over your descriptors — use FD_ISSET
to see whether there is any activity on that file.通常,您将 FD 添加到一个集合中,将其传递给select
,然后 - 循环返回您的描述符 - 使用FD_ISSET
查看该文件是否有任何活动。 Or, better yet, use poll
or epoll
for a much more efficient and scalable approach.或者,更好的是,使用poll
或epoll
来获得更高效和可扩展的方法。
I recommend you try to re-structure your code into a more common pattern, in order to obviate your requirement.我建议您尝试将代码重新构建为更常见的模式,以消除您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.