IOLib 的被动套接字抛出 EADDRINUSE
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当退出进程时,所有打开的文件描述符(包括网络套接字)都会关闭,这就是为什么它似乎在 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.