I understand the port mechanism for IO

xiaoxiao2021-03-06  18

It has been studied about more than 1 day of completed articles, code, and the MSDN is probably figured out what this mechanism is.

I / O completion port is a mechanism under winnt, which looks like a FIFO message queue.

For example,, for example, a server made by Winsock (as a factory), the main thread establishes a completion port (can be seen as a pipeline), then establish several threads, several threads simultaneously use the getcompletionportstatus () function Get the completion information and block itself (you can see the thread as the worker on the pipeline, and the function waiting to block itself can be seen as a wait for the line of goods), then the main thread began to listen to the loop, respond to the connection request (equivalent to the factory single). Then the client and server side can start using the WSasend / WSARECV (Source / Product Generation) function to send and receive. Because Wsasend / WSARECV is a function of I / O operation, the data in these I / O operations has not been transferred without transfer (the goods have not reached the pipeline), so the threads have been waiting. When I / O operation is completed (the goods reach the pipeline), one wait thread getcompletionportstatus () is returned, starting to perform the next code processing input (worker performing cargo processing), after processing, after processing, you can send back the processing after processing or Continue waiting for the next data reception. If there is a data arrival during the thread 1 process, the thread 1 has not been processed, and the thread 2 waiting for the thread can start working.

The advantage of this is that there is no need to correspond to a thread, thereby saving the number of threads. Just need to build a number of concurrent threads in advance (how to determine the specific number is asking 9CBS's cattle, but in general, it should depend on the busyness of the data exchange, too much will waste system resources, too little may make the completed port message The queue has excessive incoming that is not processed, and then the socket that has completed I / O operation is processed. The notification completed by the I / O process is sent by the system to the completed port information queue.

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

New Post(0)