Skip to main content

Module dgram

Module dgram 

Source
Expand description

Node dgram module: real UDP sockets over std::net::UdpSocket.

Threading model mirrors net (see host::run_event_loop): each bound socket runs a recv_from loop on its own thread. That thread NEVER touches the JS heap — it only moves raw datagram bytes and posts IoTask closures onto the host channel. Every JS-visible effect (emitting message/listening/close, running callbacks) happens on the main thread when the event loop runs the posted closure. The UdpSocket is shared with the recv thread through an Arc (both recv_from and send_to take &self). All main-thread records live in a thread_local, so they need no locking of their own.

Constants§

MODULE_METHODS
dgram module functions routed through stdlib::call.
SOCKET_METHODS
Instance methods on a dgram.Socket (for instance_has_method / dispatch).
SOCKET_TAG
The dgram.Socket @@native tag.

Functions§

call
stdlib::call entry for dgram.<method>.
create_socket
dgram.createSocket(type[, callback]) or dgram.createSocket(options[, callback]). type is 'udp4'/'udp6'; an options object reads its .type. A callback is registered as a one-time-per-emit 'message' listener (Node semantics).
instance_call