Windows 上最好的 epoll/kqueue/select 等效项是什么?

发布于 2024-07-05 08:49:26 字数 152 浏览 4 评论 0原文

Windows 最好的 I/O 事件通知工具是什么?

最好的意思是...

  1. 对输入文件描述符的数量没有限制
  2. 适用于所有文件描述符(磁盘文件,套接字...)
  3. 提供各种通知模式(边缘触发,限制触发)

What is Windows' best I/O event notification facility?

By best I mean something that ...

  1. doesn't have a limit on number of input file descriptors
  2. works on all file descriptors (disk files, sockets, ...)
  3. provides various notification modes (edge triggered, limit triggered)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

-残月青衣踏尘吟 2024-07-12 08:49:26

在Windows中,异步操作是通过文件操作完成的,而不是通过描述符完成的。 有多种方法可以异步等待文件操作完成。

例如,如果您想知道网络套接字上的数据何时可用,请在套接字上发出异步读取请求,当请求完成时,数据可用并已被检索。

在 Win32 中,异步操作使用 OVERLAPPED 结构包含有关未完成 IO 操作的状态。

  1. 将文件与 IO 完成端口 关联并调度异步 IO 请求。 当操作完成时,它将在队列中放置一条完成消息,您的工作线程可以等待该消息并在消息到达时检索该消息。 您还可以将用户定义的消息放入队列中。 完成端口可以使用多少个文​​件或排队消息没有限制
  2. 使用事件分派每个 IO 操作。 与操作关联的事件在完成时将发出信号(满足等待)。 使用 WaitForMultipleObjects 来立即等待所有事件。 这样做的缺点是只能一次等待 MAXIMUM_WAIT_OBJECTS 对象 (64)。 您还可以同时等待其他类型的事件(进程/线程终止、互斥体、事件、信号量)
  3. 使用 线程池。 线程池可以等待无限数量的对象和文件操作并执行 用户定义的函数 完成每个函数后。
  4. 使用 ReadFileExWriteFileEx 到队列对调用线程的异步过程调用 (APC)和 SleepEx (或 WaitFor{Single|Multiple}ObjectsEx) 和 Alertable TRUE 在每个操作完成时接收通知消息。 该方法类似于IO完成端口,但仅适用于一个线程。

Windows NT 内核在内部不区分套接字、磁盘文件、管道等文件操作:所有这些选项都适用于所有文件类型。

In Windows, async operations are done by file operation, not by descriptor. There are several ways to wait on file operations to complete asynchronously.

For example, if you want to know when data is available on a network socket, issue an async read request on the socket and when it completes, the data was available and was retrieved.

In Win32, async operations use the OVERLAPPED structure to contain state about an outstanding IO operation.

  1. Associate the files with an IO Completion Port and dispatch async IO requests. When an operation completes, it will put a completion message on the queue which your worker thread(s) can wait on and retrieve as they arrive. You can also put user defined messages into the queue. There is no limit to how many files or queued messages can be used with a completion port
  2. Dispatch each IO operation with an event. The event associated with an operation will become signaled (satisfy a wait) when it completes. Use WaitForMultipleObjects to wait on all the events at once. This has the disadvantage of only being able to wait on MAXIMUM_WAIT_OBJECTS objects at once (64). You can also wait on other types of events at the same time (process/thread termination, mutexes, events, semaphores)
  3. Use a thread pool. The thread pool can take an unlimited number of objects and file operations to wait on and execute a user defined function upon completion each.
  4. Use ReadFileEx and WriteFileEx to queue Asynchronous Procedure Calls (APCs) to the calling thread and SleepEx (or WaitFor{Single|Multiple}ObjectsEx) with Alertable TRUE to receive a notification message for each operation when it completes. This method is similar to an IO completion port, but only works for one thread.

The Windows NT kernel makes no distinction between socket, disk file, pipe, etc. file operations internally: all of these options will work with all the file types.

赠意 2024-07-12 08:49:26

libuv

libuv 为 Unix 和 Windows 提供事件 I/O,并支持套接字、文件和管道。 它是 Node.js 的平台层。

更多详细信息请访问:http://nikhilm.github.io/uvbook/introduction.html

libuv

libuv offers evented I/O for Unix and Windows and has support for socket, files and pipes. It is the platform layer of Node.js.

More details are at: http://nikhilm.github.io/uvbook/introduction.html

夕色琉璃 2024-07-12 08:49:26

据我所知,还没有一个。 我和一个朋友正在开发一个开源 Windows epoll 实现(链接如下),但我们在弄清楚如何使其与 Linux 实现的行为相同方面遇到了问题。

当前的障碍:

  • 在Linux中,文件描述符和套接字描述符是可以互换的,但在Windows中则不能。 两者都必须与 epoll 实现兼容。
  • 在 Windows 中,获取内核事件非常棘手……这就是 epoll 在 Linux 中的工作原理。 我们猜测使用我们的跨平台 epoll 库的程序在 Windows 中的运行速度将明显慢于 Linux。

随着项目取得进展,我会尝试回来更新这篇文章。

http://sourceforge.net/projects/cpoll

There isn't one yet, as far as I am aware. A friend and I are working on an open source Windows epoll implementation (link below) but we're running into issues figuring out how to make it act the same as the Linux implementation.

Current obstacles:

  • In Linux, file descriptors and socket descriptors are interchangeable, but in Windows they are not. Both must be compatible with an epoll implementation.
  • In Windows it's quite tricky to get kernel events... which is how epoll works in Linux. We're guessing that a program using our cross-platform epoll library will run noticeably slower in Windows than Linux.

I'll try to come back and update this post as we make progress with the project.

http://sourceforge.net/projects/cpoll

因为看清所以看轻 2024-07-12 08:49:26

select() 函数是 POSIX 函数,可在 Windows 上使用,包括“winsock.h”或“winsock2.h”。

select() function is POSIX and usable on windows including "winsock.h" or "winsock2.h".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文