saghul / txiki.js

A tiny JavaScript runtime
MIT License
2.54k stars 171 forks source link

Event based api for receving socket data #300

Open lal12 opened 2 years ago

lal12 commented 2 years ago

Currently you have to call recv in a loop on an UDP socket. So you have to specify a buffer of a fixed size, which might be too small or too large.

One solution would be to just return an allocated buffer if undefined is passed to recv. However IMHO an (alternative) event/callback based API would be more suitable, since it is more in line how libuv works. Currently libuv is registering and unregistering a callback on each recv(…).

This also applies for TCP sockets, though I didn't look at that in detail.

saghul commented 2 months ago

I may reevaluate this, in the context of https://github.com/saghul/txiki.js/issues/640