IOLib 的被动套接字抛出 EADDRINUSE

发布于 2024-12-23 02:25:03 字数 575 浏览 1 评论 0原文

IOLib允许创建一个被动套接字来监听客户端的连接,在调用listen之前,我们需要调用(bind-address)将套接字绑定到指定的地址/端口。

好吧,问题是,我第一次将套接字绑定到端口时,它运行良好,然后我在 slime 中使用 Cc Cc 终止线程,并再次运行程序,这次它抛出 EADDRINUSE 异常:

 <SOCKET-ADDRESS-IN-USE-ERROR 98 :EADDRINUSE "address already in use", FD: 10>

我已经像这样将reuse_addr选项设置为bind-address:

   (bind-address socket
                 +ipv4-unspecified+
                 :port 1080
                 :reuse-addr t)

但我不认为这是问题,因为当我在C中做同样的事情时,我使用Ctrl+C来终止进程,我可以重新绑定端口,但是在粘液,唯一的解决办法就是重启emacs,确实不方便,请问如何解决这个问题,谢谢。

IOLib allows to create a passive socket to listen the clients' connection, before listen is called, we need to call (bind-address) to bind the socket to an specified address/port.

Well, the problem is that the first time I bind the socket to a port, it runs well, then I use C-c C-c in slime to terminate the thread, and run the program again, this time it throws out exception of EADDRINUSE:

 <SOCKET-ADDRESS-IN-USE-ERROR 98 :EADDRINUSE "address already in use", FD: 10>

I already set the reuse_addr option to bind-address like that:

   (bind-address socket
                 +ipv4-unspecified+
                 :port 1080
                 :reuse-addr t)

But I don't think this is the problem, because when I did the same thing in C, I use Ctrl+C to terminate the process, I can rebind the port, but in slime, the only solution is to restart emacs, it's really not conveninent, so How can I solve this problem, thanks.

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

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

发布评论

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

评论(1

水水月牙 2024-12-30 02:25:03

当退出进程时,所有打开的文件描述符(包括网络套接字)都会关闭,这就是为什么它似乎在 C 中工作但在 CL 中不起作用。然而,当线程终止时,这种情况就不会发生。您会发现通过在 SLIME 中使用 restart-inferior-lisp 命令可以获得所需的行为。

然而,并非一切都丢失了。如果以 UNWIND-PROTECT 形式将函数包装在线程中,则可以安排在函数退出时关闭套接字。

When you exit a process, any open file descriptors (including network sockets) are closed, which is why it seems to work in C but not in CL. When a thread terminates, however, this doesn't happen. You'll find that you'll get the desired behavior by using the restart-inferior-lisp command in SLIME.

Not all is lost, however. If you wrap the function in the thread in an UNWIND-PROTECT form, you can arrange for the socket to be closed when the function is exited.

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