Windows上最好的epoll / kqueue / select equvalient是什么? [英] What is the best epoll/kqueue/select equvalient on Windows?

查看:213
本文介绍了Windows上最好的epoll / kqueue / select equvalient是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

最好的意思是...


  1. 没有输入文件描述符数量限制

  2. 适用于所有文件描述符(磁盘文件,套接字等)

  3. 提供各种通知模式(边缘触发,限制触发)


推荐答案

在Windows中,异步操作由文件操作完成,不是描述符。有几种方法可以等待文件操作异步完成。

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.

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

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


  1. 将文件与 IO完成端口并调度异步IO请求。当一个操作完成时,它会在你的工作线程可以等待的队列上放置一条完成消息,并在它们到达时检索。您还可以将用户定义的消息放入队列中。对完成端口可以使用多少文件或排队消息没有限制

  2. 使用事件调度每个IO操作。与操作关联的事件将在完成时发出信号(满足等待)。使用 WaitForMultipleObjects 立即等待所有事件。这样做的缺点是只能一次等待 MAXIMUM_WAIT_OBJECTS 对象(64)。您还可以同时等待其他类型的事件(进程/线程终止,互斥,事件,信号量)。

  3. 使用线程池。线程池可以使用无限数量的对象和文件操作来等待并执行完成后的用户定义函数

  4. 使用 ReadFileEx WriteFileEx 排队异步过程调用(APC)到调用线程和 SleepEx (或者 WaitFor {Single | Multiple} ObjectsEx ),带有 Alertable TRUE ,以便在每个操作完成时收到通知消息。此方法类似于IO完成端口,但仅适用于一个线程。
  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.

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

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.

这篇关于Windows上最好的epoll / kqueue / select equvalient是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆