Skip to content

linux-0.1.6-test5 对僵尸套接字的修复 ​

首次公开证据

打开首次公开证据
查看 1 个交叉存档
来源说明

Published on GitHub in February 2024 as part of Martti Malmi's testimony in the COPA v. Wright trial

测试 5:

我在 send 和 recv 调用中加入了 MSG_DONTWAIT,以防它们忘记套接字是非阻塞的。如果这样还不行,现在还有一个兜底方案:由另一个线程监视 send/recv 线程,如果它停止运行,就将其终止并重启。它会在 debug.log 中打印“*** Restarting ThreadSocketHandler ***”,状态栏也会显示一会儿错误消息。

在终止之前,它会尝试关闭挂起的套接字。如果成功,就不必诉诸终止。

我做了一个测试,让它终止线程约 1000 次而没有出问题,所以应该是安全的。Linux 上的 terminate 是 pthread_cancel,它会将线程抛进 C++ 的异常处理程序。

我们使用的线程调用没有 terminate,所以我在 util.h 中创建了自己的封装,在 Windows 上使用 CreateThread,在 Linux 上使用 pthread_create,而不是: _beginthread 仅适用于 Windows,而且没有 terminate boost::thread 确实很有吸引力,但没有 terminate wxThread 要求你为每个可能调用的函数创建一个类(真讨厌)

文件将在下一封邮件中附上

英文原文 ​

展开英文原文

test 5:

I added MSG_DONTWAIT to the send and recv calls in case they forgot the socket is non-blocking. If that doesn't work, there's now the catch-all solution: another thread monitors the send/recv thread and terminates and restarts it if it stops. It prints "*** Restarting ThreadSocketHandler ***" in debug.log, and an error message displays on the status bar for a while.

Before terminating, it tries closing the socket that's hung. If that works, it doesn't have to resort to terminating.

I ran a test where it terminated the thread about 1000 times without trouble, so it should be safe. The terminate on linux is pthread_cancel, which throws it into C++'s exception handler.

The thread calls we were using didn't have terminate, so I created our own wrappers in util.h to use CreateThread on windows and pthread_create on linux, instead of: _beginthread is windows only and lacks terminate boost::thread is really attractive, but lacks terminate wxThread requires you to create a class for every function you might call (yuck)

File attached in the next e-mail

为历史保存,为中文读者整理。每篇档案均附来源与英文原文。