使用.NET螺纹异步套接字?螺纹、NET

2023-09-06 22:27:23 作者:宿醒

从 http://msdn.microsoft.com/en-us/library /bbx2eya8.aspx 看起来,这种类型的插座都使用多个线程,但我在想什么异步套接字可以而且应该在单个线程(或线程的最少数量有限)运行,因为它们只是从状态机的工作原理是智能调度的回调。

From http://msdn.microsoft.com/en-us/library/bbx2eya8.aspx it looks like, that this type of sockets are using more than one thread, but from what i am thinking Asynchronous Sockets can and should run in single thread (or least limited number of threads) , since they are just callbacks from state machine which works like smart scheduler.

我的问题是:是否异步套接字派生尽可能多线程,因为有连接,或者是有一些上限多少线程都产生了,不管有多少连接应用程序处理。

My question is: Does asynchronous sockets spawns as many threads as there are connections or is there some upper bound of how many threads are spawned, no matter how many connections application handles.

推荐答案

是的,没有。所有的真正的工作是由TCP / IP驱动程序堆栈完成。其中有没有问题处理多个不完整的IRP请求。当其中一人完成,一个APC是发射一个线程池线程从而结束调用你的完成回调。底层操作系统对象被称为I / O完成端口,则可以在此阅读更多关于它的 SDK文章。

Yes and no. All the real work is done by the TCP/IP driver stack. Which has no trouble handling multiple incomplete IRP requests. When one of them completes, an APC is fired on a threadpool thread which in turn ends up calling your completion callback. The underlying operating system object is called an "I/O completion port", you can read more about it in this SDK article.