Home > Software engineering >  IOCP socket reuse
IOCP socket reuse

Time:09-22

Recently an integrated project debugging communication interface, in order to make full use of multi-core CPU, understanding learning IOCP model - learn a little experience, not comprehensive network monitoring is to perfect the implementation, the client, a TCP connection, a serial port, HID, UDP client, named pipes and its implementation, version 1.0 debugging good, are not satisfied, disconnects processing aspects of the problems, explore the author here:
Such as TCP connection, the server-side call DISCONNECTEX, if the client does not call corresponding DISCONNECTEX or closesocket - such as a third party to do the client, the server doesn't receive feedback, version 1.0, the server-side closesocket directly, can have the function of disconnected, but can't reuse a socket,
2. If the server and the client are have DISCONNECTEX function, design thought if the received data length is 0, then DISCONNECTEX, this connection can be completely cut off of the "elegant" but shall only be DISCONNECTEX first, SEND the recipient receives data length is 0, then also DISCONNECTEX, the sender received feedback, disconnect the connection grace,

Now have the following questions
1. The server-side implementation socket reuse have how old? I do is the Internet of things has around 1000 users online at the same time, also can constantly disconnect reconnection - 2 g network is not stable, the server needs to solve real-time close illegal connection, maximum efficiency of concurrent...
2. 2 in front of the train of thought practice effectively, whether it is right, is there any way to solve the client sends, the server receives, the server can DISCONNECTEX and disconnected; Heartbeat mode, the server should receive terminal data, and to send a heartbeat packet (right?) After, take the initiative to DISCONNECT the client response disconnected, is everything OK, you did this?

CodePudding user response:

The server socket how to implement? I understand that the socket is broken again, it is not a value, and the socket is an unsigned integer, there is no create time-consuming problem,
Server-side IOCP application should always deliver recv request, once the client disconnects should activate the callback function and the received data for 0. Do not know the client do not call closesocket will, so forget,

CodePudding user response:

1000 users online at the same time
The select IO model will do the trick,

CodePudding user response:

reference 1st floor youyingbo response:
server socket how to implement? I understand that the socket is broken again, it is not a value, and the socket is an unsigned integer, there is no create time-consuming problem,
Server-side IOCP application should always deliver recv request, once the client disconnects should activate the callback function and the received data for 0. Do not know the client do not call closesocket will, so forget,


So-called disconnect, abnormal were found when receiving, receiving the first packet data timeout, receiving data at the back of the timeout, and so on and so forth, call DISCONNECTEX disconnected; Then this SOCKET can continue as accept parameters, waiting for the next client access, found that only receive abnormal (should be the client disconnected or abnormal exit), immediately return IO events; Other cases need to wait for the client disconnect - if the broken process time longer timeout, can only call closesocket forcibly disconnected, SOCKET will not be able to reuse the right now??????? ,

The question is: if the client is open, may be illegal users; Must be finished by closesocket and cannot reuse the socket? It is necessary to reuse? Closesocket connection problems, and then a new socket have much effect on performance?

CodePudding user response:

Should be to let the normally closed socket (such as the user closes the client, workthread can receive the end of the link socket), list the end, reset waiting to use,

Your heartbeat package, don't reply the socket, use closesocket, then to apply for a new socket resource. List the end, a new wait for use,

CodePudding user response:

The SOCK reuse seems not very much, but not good maintenance, it is good to deal with business

CodePudding user response:


When the client abnormal disconnect after SOCKET, DisconnectEx delivery can return immediately;
But in dealing with a timeout in the Server side Client, delivery needs to wait for a while to return, and return to the time not sure
https://blog.csdn.net/tpriwwq/article/details/18077091

If the concurrency value at around 1 k,
The individual feels don't need to do optimization in this area
  • Related