sockets - OCaml 刷新奇怪的行为(退出所有线程)
问题描述
我尝试使用 2 个命令实现 CLI:
run
生成一个unix套接字/my/path/file.sock
并产生输出watch
连接到套接字并将输出转发到自己的输出
当我杀死watch
命令时,我无法理解为什么run
命令也被杀死。它们不会引发任何异常或 sys 信号。我注意到问题来自flush
功能。一旦被调用,它就像一个exit 0
. 怎么来的?
解决方案
服务器必须侦听客户端断开连接并从连接列表中删除连接。像这样的东西可能会起作用:
let client_thread conn =
let in_ch = in_channel_of_descr conn in
while true do
try input_line in_ch |> ignore
with End_of_file ->
(* Remove conn from !conn and close the conn *)
done
in
let add_conn () =
(* ... *)
Thread.create client_thread conn |> ignore;
(* ... *)
in
推荐阅读
- loops - 在 Qlik Sense 中循环数月
- python - 使用python搜索视频后如何获取YouTube视频的全名?
- visual-studio-code - 如何在 Visual Studio Code (VSCode) 中将 markdown 主题更改回默认值?
- powershell - get-winevent 输出到以二进制形式存储的文件
- python - 没有这样的文件或目录“优化图像”
- html - 如何在 vue.js 顶部导航栏的右侧添加内容和图标?
- javascript - 使用 Typeorm 在某个日期之前或之后从 sqlite3 中选择数据
- javascript - 使用getStaticProps Next js时如何填充useSelector的日期
- java - 为什么在 Java Lambda 表达式中使用函数式接口
- python - Flask:在一个页面中多次使用相同的模板