After a period of research and study, I have a certain understanding of the iocp principles and procedures. The test demo results show that about 5000 connections can be easily processed in the LAN, it is still relatively stable. Several hours after running the echo test. The server memory is stable at about 60 MB.
In the past two days, the original code is encapsulated into an iocp class.
The original API call is good for studying and learning iocp principles. It may be hard to understand if there are no good documents after encapsulation.
1. Data Transmission Flowchart
2. Service write-back data process
2. iocp object Center
2.1 tiocpobject
In the iocp object center, create an iocp handle and enable the listener port.
It can process data, receive sockets, send and receive requests, and send requests.
2.2 tiocpclientcontext
Socket extensions
Receives data,
It can inherit its datarecvied for data processing.
You can call it to write data back to the client.
2.3 tiocpclientcontextfactory
Creates and releases socket extension objects <used when receiving client connections>
Registers encoder and decoder
Registers the socket extension object class <class that inherits tiocpclientcontext>
2.4 tiocpdecoder
The decoder called after receiving data from the client decodes the received data stream into an object.
You can handle the sticking package here.
You need to register the decoder with tiocpclientcontextfactory
2.5 tiocpencoder
When tiocpclientcontext is called to write back an object to the client, it is encoded as a data stream. Then it is sent to tiocpobject for data delivery.
Register the encoder with tiocpclientcontextfactory