【发布时间】:2016-08-15 06:58:35
【问题描述】:
我有一个简单的端口应用程序(字面意思是来自 Erlang -- Ports documentation 的示例)和一个控制其使用的 GenServer。
GenServer 可以与 C 应用程序正常通信,但它不会收到响应,iex 或其主管会收到响应。如果我从 iex 调用 flush,我会看到预期的消息。
如果我创建一个单独的模块并从中产生一个接收循环,它仍然不会收到端口响应消息。
我感觉我错误地打开了端口,但无法证明这一点。有什么明显的我搞砸了吗?
port = Port.open({:spawn, "./extprg"}, [{:packet, 2}, :exit_status])
collect = fun () -> collect_results(port) end
spawn(collect)
def collect_results(port) do
receive do
{^port, {:data, data}} ->
#never gets called despite matching messages in flush
{^port, {:exit_status, status}} ->
#never gets called...
{:increment, value} ->
Port.command(port, [1, value])
collect_results(port)
end
end
【问题讨论】:
标签: elixir erlang-ports