监听套接字意外终止

发布于 2024-08-02 18:41:33 字数 271 浏览 6 评论 0原文

我遇到一个问题,TCP 套接字正在侦听端口,并且已经完美工作了很长一段时间 - 它处理了多个连接,并且似乎工作完美。但是,有时当调用accept()创建新连接时,accept()调用失败,并且我从系统中收到以下错误字符串:

10022:提供了无效的参数。

显然这可能会发生当您在不再侦听的套接字上调用accept()时,但我自己没有关闭套接字,并且没有收到该套接字上的任何错误通知。

任何人都可以想到侦听套接字停止侦听的任何原因,或者如何生成上述错误?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

围归者 2024-08-09 18:41:33

一些可能性:

  • 代码的其他部分覆盖了句柄值。检查它是否已更改(在其他地方保留副本并进行比较、打印出来、在调试器中写入时设置断点等)。

  • 有东西关闭了手柄。

  • 与有问题的 Winsock LSP 交互。

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.

书间行客 2024-08-09 18:41:33

我想到的一件事是系统待机或休眠模式。我不确定winsock 库如何处理这些事件。可能是网络接口(部分)关闭。

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.

栀梦 2024-08-09 18:41:33

调试套接字的线程(使用 IDE 或通过反汇编程序)并观察其执行情况以查找可能导致其停止侦听的任何内容可能是有意义的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文