Posted on 2007-09-29
I'm using CAsyncSocket in a Dialog app to communicate with network devices. The problem I am having is it throwing an exception when I call sock.Close() (if the socket creation/connection has failed). Because its async I dont wait around for it to connect... it gives me the WSAEWOULDBLOCK error which is to be expected. However at some point the connection times out, and in my restart code I call 'Close()' to clean up the socket. If the original connection failed it throws an exception.
I also get an exception if the Create call was successful, then the Connect failed, then I call Create again.
So basically I need a failsafe Close() call that I can make, or a way to avoid these exceptions (BTW Try Catch does not help).