When can I close CAsyncSocket?

CAsyncSocket deletes my application if I remove CAsyncSocket after a call to Connect , but before the OnConnect callback was called. ASSERT(pSocket != NULL) terminates with a CAsyncSocket::DoCallBack , and the application terminates.

In other words, if I create CAsyncSocket , try connecting it to the server, and then kill it before this connection either succeeds or I have problems. I can avoid this particular failure by running OnConnect and setting a flag that indicates that the connection attempt is complete. If the flag is false, I know that it is not safe to delete.

Are there any other cases that need to be checked before I delete the object? Is there a single way to check if this is safe? Or do I need to implement all callbacks for any operation that I could initiate ( OnReceive , OnSend , OnConnect ) and ensure that these calls are called?

+6
source share

All Articles