Complete port (on)

zhaozj2021-02-17  58

Complete port mode

Completion port is the most complex input and output mode so far. However, when an application has to handle a large number of sockets, it also provides the possibility of achieving system performance. Unfortunately, the completion port can only be used on Windows NT and Windows2000. Since the completion of the port is designed to be extremely complicated, it should be a programmer's youth, only when they are forced to face hundreds or even thousands of concurrent sockets, you want to get better Scale after adding the CPU. It was sent to the battlefield. About completing the port, the most important thing is to remember this: If you develop a high-performance service for a large Socket I / O request for Winnt / 2000, it is your best choice (such as a web service).

Essentially the port mode requires that you create a Win32 Complete port object to manage overlap I / O requests, with a certain number of threads to process completed overlapping I / O requests. Note that the end is Win32, WinNT, Win2000 Built-in, it can operate more than just a Socket handle. However, this chapter will limit the scope of the discussion to how to use completion ports in the Socket handle context. Before starting using completion port mode, we must create a completed port object that uses it to manage the multi-I / O requests on any number of Socket handles. Complete this action requires calling the CreateiocompletionPort function, which has the following form: Handle CreateiocompletionPort (Handle FileHandle, Handle ExistingCompletionport, DWord NumberofconCurrentThreads);

Before you understand the details of the parameters, you must understand that this function has two purposes:. Create a completed port object. Associate a handle to the completion of your port. When starting to create a completed port, our only interested parameters are NumberOfConcurrentthreads, and the three parameters in front can be ignored. The parameter NumberOfConcurrentThreads is used to specify the number of threads that can be concurrent on a completion port. Ideally, only one thread is run on one processor, which avoids the overhead of the thread context. If the value of this parameter is 0, it is to tell the system thread number as the number of processors. We can create I / O completion ports with the following code. CompletionPort = CreateiocompletionPort (Invalid_Handle_Value, NULL, 0, 0); This code returns a handle that is used to identify the completion port here when the Socket handle is associated.

Worker thread and complete port

转载请注明原文地址:https://www.9cbs.com/read-29782.html

New Post(0)