3

我想为 node.js 创建一个本机 (c++) 模块,它能够将套接字发送到另一个节点进程,这与当前进程完全无关。为此,我坚持使用辅助库,它有一个非常非常简单的 API。我现在要解决的问题是如何获取 node.js 的 fd 或套接字对象的句柄。

tcp_wrap.cc&中有一个 TCPWrap 类tcp_wrap.h,它有一个名为 的属性handle_,它包含一个uv_tcp_t来自 libuv 的对象,但该属性是私有的。我也不能#include,因为它只是 node.js 的一个模块,而不是直接在 node.js 本身中。我不知道将源文件复制到我的模块中是否是一个好主意只是为了获得那个类......

你有什么想法我该怎么做吗?

我不必在windows上运行,很难。

谢谢!

4

1 回答 1

1

I finally found a way to do it. You can find the node module here: https://github.com/VanCoding/node-ancillary

I've just taken the headers "tcp_wrap.h","stream_wrap.h" and "handle_wrap.h" and then included "tcp_wrap.h".

I could then get the object the following way:

TCPWrap* wrap = static_cast<TCPWrap*>(args[0]->ToObject()->GetPointerFromInternalField(0));
StreamWrap* s = (StreamWrap*)wrap;

The following code then gives access to the file descriptor

s->GetStream()->fd
于 2012-04-03T09:20:58.213 回答