c - 从 C 向 GenServer 发送消息
问题描述
如何向远程 Elixir GenServer 发送消息,然后使用C Erlang 接口接收调用结果?
我想在 C 中运行类似于
{result1, result2} = GenServer.call(MyModule.NodeName, {:dothing, "blah"})
这是我到目前为止所拥有的。它编译并连接到远程服务器并运行ei_reg_send
而不会导致错误,但远程服务器没有收到响应。(我打开了一个记录器,所以我知道什么时候来电。)
#include <erl_interface.h>
#include <ei.h>
#define COOKIE "cookieval"
#define HOST "name@host"
int main() {
ei_init();
ei_cnode ec;
int n = 0;
int sockfd;
int self;
if((self = ei_connect_init(&ec, "nss", COOKIE, n++)) < 0) {
return 1;
}
if((sockfd = ei_connect(&ec, HOST)) < 0) {
return 2;
}
ei_x_buff request;
ei_x_new(&request);
ei_x_format(&request, "{dothing, ~a}", "blah");
if(ei_reg_send(&ec, sockfd, "MyModule.NodeName", request.buff, request.index) < 0) {
return 3;
}
ei_x_free(&request);
// code makes it to here, but there's no indication that the genserver was called
return 0;
}
解决方案
你不能GenServer.call/2
在 C 节点中做。至少不是直接的,因为这不是公共 API,在这种情况下消息的外观如何(不是说它改变了很多,但你不能依赖它)。相反,您可以做的是发送常规消息并在handle_info
.
推荐阅读
- reactjs - 替换后历史推送
- hyperledger-fabric - 无法更改在线 Composer Playground 的版本
- java - 即使数组不是那么大,为什么我要为这个简单的任务得到超时错误?
- ruby-on-rails - Rails 5 在 Wicked PDF 中显示值
- javascript - 我可以从 passport-auth-token 获取标头参数吗
- r - 重新编码调查多项选择题的输出
- keycloak - 从 keycloak 3.2.1 升级到 4.5 时出错
- javascript - Mouseenter 事件正在跳过元素
- python - py2exe打包的.exe文件无法运行
- docker - 使用 Upstart 作为初始化系统时如何设置 Docker Daemon 的内存限制?