Home > Software engineering >  IOCP accept, closesocket () program crashes
IOCP accept, closesocket () program crashes

Time:09-27

Using IOCP and accept, after construction of CP and thread pool, the client sends data to the server, the server to the client sends data of each connection is no problem, but on the client side using closesocket () after closed connected to the server, the server with the getqueuedcompletionstatus inspection, according to the obtained data is 0, on the server with closesocket () disconnect with the client, then we have a problem, like getqueuedcompletionstatus made many times 0, basic in 3-8 times, which the great spirit analysis to analyze O (studying studying) O ha!

CodePudding user response:


Multi-threaded project, set up/MT/MD? Especially/ML

CodePudding user response:

If a socket is abnormal, and the socket on the related delivery will return
This time, just need to pay attention to.
Socket has been closed, will not be able to call closesocket again

CodePudding user response:

Has been solved, thank you!
In that I got the CP IO after the event, the client to Send information, adopted the WSASend (), now into the Send (), it's no problem,

CodePudding user response:

Or synchronization problem, consider a lot,
As the second floor says, close the socket can't repeat
Can check whether the socket INVALID_SOCKET before closing, closed the socket is about to set a socket to INCALID_SOCKET
Before closesocket to consider other conditions, such as have not completed the IO request (closesocket will cancel the outstanding requests), and the request of the other threads are dealing with the same socket, then shut down will collapse (not close the socket causing collapse, but similar to the delete action caused by overlapping structure), must use synchronous socket, such as processing is complete to shut down,
  • Related