Archived

This topic is now archived and is closed to further replies.

Unhandled Exception & Winsock :: Winsock

This topic is 5587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I am working on a winsock program that supports multiple connections simultaneously. For example, the user could connection to more than one server at any given time. The design works, but it fails if the user cancels. In other words, if the user lets the program finish doing work no matter how many connections the user has selected, then the program works. However, if the user cancels via cancel button that sets a status variable in the program to false, then the program begin closing all connections and closing all worker threads. I am still trying to fingure out what causes the program to crash. Visual C++ outputs this error. ----- Unhandled exception at 0x77f5111b in myProgram.exe: 0xC0000008: An invalid HANDLE was specified. ----- Does anyone know what is a good place to start debugging this kind of error? I check all thread handle via WaitForSingleObject() before closing. I use a linked list to store the threads handles. Thanks, Kuphryn

Share this post


Link to post
Share on other sites
Okay. Thanks.

I believe I know a place to start debugging the problem now. I think the problem has to do with the fact that if when the user cancels, everything in the program collapse. In other words, the program tries to shutdown everything and I believe each connect tries to shutdown all sockets multiple times.

Maybe the problem is as everything tries to shutdown the sockets and worker threads, somewhere there is there is an invalid thread.

Weird!

Kuphryn

Share this post


Link to post
Share on other sites
0x00000008 is a double fault. Somewhere when the system is trying to put together an error message, it faults again.

It''s not the kind of error that happens often. It could be a thread is closed down before winsock is and winsock is trying to report an error to that thread. Only you can find out.

Share this post


Link to post
Share on other sites
Okay. Thanks everyone. I know the problem and has implemented a working solution.

smanches was right on the right track about the threads closing simultaneously. I did in fact set all threads to INVALID_HANDLE_VALUE and checked them all using WaitForSingleObject().

The problem has to do with collapsing all sockets and threads as the user cancels a process. A solution I now use is to close each socket which means all their worker threads after their threads ends and sends a messages to main frame for closing. In other words, instead of stepping through all sockets in the linked list and closing them and their worker threads, now the program waits for them to end since I am using a boolean variable to indicate cancelation. This solution works flawlessly.

Kuphryn

Share this post


Link to post
Share on other sites