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

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

问题描述

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

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

我最好的意思是......

By best I mean something that ...

  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. 使用 ReadFileExWriteFileEx异步过程调用 (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 equivalient 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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