The Adventure Island thread is a worker thread executed on the iocp port, which continuously calls windowsapi functions.
The getqueuecomplctionstatus function is used on the iocp port to query whether asynchronous fo operations are completed.
. If an asynchronous 1/0 operation is completed, the asynchronous 1/0 operation is processed accordingly. If no,
Wait. The Adventure Island thread is a very busy thread, which needs to be processed continuously on the iocp, then the system needs
Research and Implementation of 3l network game server network engine
How many threads do I need to start? Generally, to improve performance, the number of started threads is processed by the system.
Is twice the size of the device.
The Adventure Island thread is implemented by the [ireadproc function under worker in the cnetserver class. What is shown in Figure 4.4 Is
The sequence diagram of the server thread. In the sequence diagram, getqueuecompletionstatus indicates whether to use this function to check whether
There are completed overlapping fo. Erro: Indicates error handling when an error occurs, and acceptcompleted indicates receiving operation.
Readcompleted indicates the processing when the read operation is completed, and writecorrtpleted indicates the write operation.
Processing when done.
The specific implementation steps of the adventure island thread are as follows:
(1) The Adventure Island thread enters the loop; it constantly calls the getqueuedcompletionstatus function to check whether there is any
The overlapping fo operations are completed.
(2) If no overlap operation is completed, wait. If overlapping operations are completed, check whether the socket is
If an error occurs, handle the error accordingly. If no error exists, the corresponding event is processed.
(3) If an overlapping acceptexfo operation is completed, it indicates that a new customer gateway is connected to the server,
Apply for the customer context (CCI) object for the new connection, and associate the new connection with the iocp object.
(4) If an overlapping read operation is completed, it indicates that data has arrived. In this case, the data should be read.
The data must be read sequentially, that is, according to the NC Ding enireadsequen 'e variable in the unique data structure of the handle.
. After reading the data, you can use the yyreadcompleted interface to notify the upper layer of the function.
Layer.
(5) If an overlapping write operation is completed, the data is successfully sent to the client .) Send Data Communication
The policywritecompleted interface function informs the upper layer that the upper layer can handle the problem accordingly.
4.2.6 virtual function interface
As the bottom layer of the engine, data interaction with the upper layer is required. Therefore, we have designed some virtual function interfaces,
Through the virtual function interface to complete data interaction, the upper layer needs to inherit and re-implement these virtual functions during implementation
The cnetserver class has the following virtual functions:
(L) virtualvoidnotifyconnectionestslblished (cclientcontext * pcont, from
Cclientbu month Fly R * pbufl Fly R); this function is called when the connection is established, that is, the client uses the connect function to connect to the server
If the connection can be established at the server end, this function is called at the server end. Upper-layer implementation classes if the connection is established
To process data, you must rewrite this function.