Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call into Node's libuv APIs (uv.h) #941

Open
CMCDragonkai opened this issue Nov 13, 2022 · 2 comments
Open

How to call into Node's libuv APIs (uv.h) #941

CMCDragonkai opened this issue Nov 13, 2022 · 2 comments

Comments

@CMCDragonkai
Copy link

I'm coming from implementing native addons in NodeJS with C++ using the Node API.

I'm trying to integrate the rust library quiche into NodeJS.

The usage of quiche requires the ability to bind to addresses and open UDP sockets.

In quiche's examples, they show how to do this with mio inside Rust, or with libev in their C examples.

However we know, NodeJS has libuv and this is what is used to handle sockets. I believe I should be using libuv to ensure that my native addon is opening sockets in the same way that the rest of the NodeJS runtime is behaving.

If I'm trying to open and bind to a socket using Neon, how do I access the libuv API that the Node runtime would be bundled with?

I saw that Rust has a libuv crate, but using a such thing would result in simply statically compiling the libuv in the resulting node addon right?

What is the equivalent to:

#include <uv.h>

For Neon?

@kjvalencik
Copy link
Member

Neon does not provide any direct hooks into libuv. At most, we would provide a pointer to uv_loop_s since that's all that Node API provides.

This could also be accessed without Neon's help.

Neon also provides high level APIs for calling back into the JavaScript VM from another thread. However, these are intended for general eventing.

@bgfist
Copy link

bgfist commented May 16, 2024

I wonder how node-gyp link those functions of libuv. After all, nodejs now only bundled with a binary executable "node", and accompanying header files, but without any dynamic library. If we know the underlying principles, we can figure out the linking options in Rust.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants