views:

194

answers:

3

Hi,

I'm having a problem where a TCP socket is listening on a port, and has been working perfectly for a very long time - it's handled multiple connections, and seems to work flawlessly. However, occasionally when calling accept() to create a new connection the accept() call fails, and I get the following error string from the system:

10022: An invalid argument was supplied.

Apparently this can happen when you call accept() on a socket that is no longer listening, but I have not closed the socket myself, and have not been notified of any errors on that socket.

Can anyone think of any reasons why a listening socket would stop listening, or how the error mentioned above might be generated?

+2  A: 

Some possibilities:

  • Some other part of your code overwrote the handle value. Check to see if it has changed (keep a copy somewhere else and compare, print it out, breakpoint on write in the debugger, whatever).

  • Something closed the handle.

  • Interactions with a buggy Winsock LSP.

janm
+1  A: 

One thing that comes to my mind is system standy or hibernation mode. I'm not sure how these events are handled by the winsock Library. Might be that the network interface is (partially) shut down.

Frank Bollack
+1  A: 

It might make sense to debug the socket's thread (either with an IDE or through a disassembler) and watch its execution for anything that might be causing it to stop listening.

Rushyo