I understand the completion port

xiaoxiao2021-03-06  62

reference:

1,

http://community.9cbs.net/expert/topic/3056/3056877.xml?temp=.8741724

2, << Windows Network Programming 2 >> Chapter 8

3,

Http://community.9cbs.net/expert/topic/2646/2646592.xml?temp=.9986383

The definition of the completion port has already been detailed in the reference 1, 2, and the reference 1 is the summary of the experience of FZD999 (flower difference). It is well written in detail. It is a good article to complete the port. Reference 2 is more important to say that it is a need for Windows network programming.

The previous use of the completed port is used is the framework mentioned in these two articles. Today, I have summed up the things that I have learned before, I found that I only know that I didn't know if I didn't know how they did it, it would be like a martial art. Quietly, find that the reference 1, 2 seems to be missing.

Reference 1 mentioned that the reference completion port is similar to the message queue (original words as: actually said that IOCP is not a message queue!), I think this statement is not very appropriate, refer 2 mentioned to complete port based Win32 overlap I / O, how does this overlap I / O explain?

Reference 3 contains an explanation of this - in order to avoid the CPU waiting for a slower I / O operation, when the CPU is in a I / O request, the system is open, The root internal thread processes the I / O request, and your thread does not hang. This is better than saying synchronous events asynchronously, and the network programming is to turn WSARECV and WSasend into an asynchronous function. In order to implement synchronization, MultiObject () and getOverLAPpedResult () can be obtained, and then the corresponding process is made accordingly.

For completion ports, after a set of knots are fixed to the completion port, WSARECV and WSasend will return immediately and improve the efficiency of the system. You can call getQueuedCompletionStatus to determine if WSARECV and WSasend are completed. This master program can wait for new connections, thread programs waiting for WSARECV and WSasend to be completed. I think this is also the real meaning of the port.

With this view, you can understand the example of Chapter 8 of Chapter 8. After the main thread accepts a connection, call the WSARECV waiting for the data sent by the connection (not blocked, the acceptance of the data is completed by the completion port). After accepting the thread function, then send it to the customer data with the WSasend function (the same, it is not blocked, returned directly, and the completion port determines whether the data is sent). This requires a distinction between the thread function to be sent or accepted. If it is sent, you need to call a WSARECV function Wait to send the data next time.

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

New Post(0)