Expand description
Node net module: TCP Server and Socket.
Threading model (see host::run_event_loop): each listener runs an accept
loop on its own thread and each accepted connection runs a read loop on its
own thread. Those threads NEVER touch the JS heap — they only move raw bytes
and post IoTask closures onto the host channel. Every JS-visible effect
(creating the Socket object, emitting connection/data/end/close,
calling listeners) happens on the main thread when the event loop runs the
posted closure. All shared Rust-side state (listener/socket records) lives in
a main-thread thread_local, so it needs no locking of its own; only the
write half of each TcpStream is shared with… nothing else, but is wrapped
for symmetry and future duplex use.
Constants§
- BLOCKLIST_
METHODS - Instance methods of a
net.BlockList(parent wires theBlockListtag toblock_list_callvianative_tag/instance_call). - MODULE_
METHODS netmodule functions routed throughstdlib::call.
Functions§
- block_
list_ call BlockListinstance dispatch (parent routes theBlockListtag here).- call
stdlib::callentry fornet.<method>.- connect
net.connect(...)/net.createConnection(...): build aSocketand start the connection immediately. Returns the socket synchronously; theconnectevent fires on the main thread once the TCP handshake completes.- constant
- Non-function
netnamespace members: the class constructors, exposed as builtin ctor namespaces so.prototyperesolves andnew net.X(...)routes throughstdlib::construct→net::construct.Streamis a legacy alias ofSocket. Reachable vianamespace_property→stdlib::constantonce the parent adds a"net" => net::constant(name)arm. - construct
stdlib::constructentry fornetclasses. Parent wires this intostdlib::construct.- create_
server - Build a
net.Server. An optionalconnectionListeneris stored on the object and invoked (plusconnectionemitted) for every accepted socket. - instance_
call - new_
emitter_ object - Build a native emitter object (
@@nativetag +@@on/@@oncelistener maps) carrying the given extra props. Shared shape withevents::new_emitterso the EventEmitter methods (on/once/emit/…) work verbatim. - new_
socket - Build a bare
net.Socket(a native emitter) with an id but no live stream, as produced bynew net.Socket().connectis called separately. - set_
conn_ hook - Attach an
http-style per-connection hook to a server object (called byhttp::create_server). Stored in the main-thread registry, keyed by the server’s assigned id once it starts listening — so we stash it on the object untillistenregisters the record. - socket_
write_ id - Write raw bytes to a live socket by id (no-op if it has closed).