Network Programming with IOCP and Thread Pool – Intro

来源:互联网 发布:整形网络平台 编辑:程序博客网 时间:2024/05/16 20:29

http://www.youngwriting.net

http://www.youngwriting.net/blog/?paged=14

These days, I’m playing with network programming with IOCP and Thread Pool just for pure fun. :) After several days of reading MSDN, articles and writing experimental codes, I’ve realized that there are pretty big changes I need to catch up.

If you still use IOCP with GetQueuedCompletionStatus() and your custom threads (like me before), you might want to follow this series of postings I will update. I will provide sample code to clarify the right way to use them.

Also, I will benchmark techniques to each other so that hopefully I can give you some guidelines about When we need to use Which technique, or, at least, help you to avoid making the same mistakes I would make while I write this series.

First of all, let’s see how many ways we can choose for using IOCP.

If we use custom threads to get I/O completion notification,

1. CreateIoCompletionPort() and GetQueuedCompletionStatus()
- Windows 2000 (Pro, Server) or later.

2. CreateIoCompletionPort() and GetQueuedCompletionStatusEx()
- Windows Vista and Server 2008 or later.

If we use Windows Thread Pool to get I/O completion notification,

3. BindIoCompletionCallback()
- Windows 2000 (Pro, Server) or later.

4. CreateThreadpoolIo(), StartThreadpoolIo() and etc
- Windows Vista and Server 2008 or later.

There also some APIs related to Thread Pool like QueueUserWorkItem(). Unfortunately, but in a good way, Thread Pool system has been completely re-written for Windows Vista and we need to use those new and richer APIs to maximize our server performance.

If it’s not confusing enough, I can tell you that there are also special socket functions which are Microsoft-specific extensions to the Windows Sockets specification. For example, ConnectEx(), AcceptEx() and etc. These functions are to fully utilize IOCP power for all IO operations including receive (read) and send (write).

Yes, it’s gonna be a long journey but it must be fun! So excited! LOL

原创粉丝点击