[quickjs-devel] Re: tcp/udp sockets

  • From: Jeremy DeJournett <jcdejournett@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Mon, 30 Jan 2023 18:14:14 -0500

Pranav,

Have you tried building your Node module in esbuild? With some minor
patching, you can then compile it to QuickJS bytecode which you can embed
in a native binary alongside the interpreter.

Here's how I did something similar a few months ago:
https://github.com/ijustlovemath/jescx/blob/master/README.md

There's a few other ways to do this, including adding your very own net and
fs objects to the global context, but I found this way to be the most
frictionless.

Best,

Jeremy

On Mon, Jan 30, 2023, 10:57 Pranav Samvith Bharadwaja <pranav@xxxxxxxxxx>
wrote:

Update:
  I found a resource on medium.

https://calbertts.medium.com/how-to-create-asynchronous-apis-for-quickjs-8aca5488bb2e
  but in this resource they use the process module to invoke the curl
command to make a http request. Perhaps the medium resource is missing
something, or they just decided to use a simple tool (curl) instead of
opening a socket and sending uri and headers?
  If tcp sockets are not implemented at all, is there any way in which I
might go about implementing a sockets built-in module for the qjs engine?
  Similarly I would like to implement a way to load local files and send
them to a remote client.
  This resource also claims that qjs uses select instead of libuv. is
there a build option using which I can choose whether to use
select/poll/epoll or libuv? or would i need to implement that as an option
in the qjs engine code as well? Is select much slower than libuv for an
application that mostly deals with io over tcp sockets and rarely ever
needs to read/write files?
I would appreciate any advice in this matter.
Thanks,
Pranav

On Mon, Jan 30, 2023 at 12:18 PM Pranav Samvith Bharadwaja <
pranav@xxxxxxxxxx> wrote:


Greetings,
  I have seen this mailchain

https://www.freelists.org/post/quickjs-devel/Newbie-Getting-something-like-require-to-work,1
  I think it is reasonable that net, fs and path are not implemented in
qjs. But is there an alternative by which we could create tcp/udp sockets?
  I am trying to compile a node.js project and with some custom edits to
some node modules, able to bundle them all into a single file (because
require doesnt work with qjs). A database driver would inevitably use the
net built-in module. If an alternative is available i could make
customization for qjs backend versus pre-existing nodejs. Any help is
appreciated.
--
Thanks and Regards,
Pranav.


Other related posts: