Skip to main content

Module net

Module net 

Source
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 the BlockList tag to block_list_call via native_tag/instance_call).
MODULE_METHODS
net module functions routed through stdlib::call.

Functions§

block_list_call
BlockList instance dispatch (parent routes the BlockList tag here).
call
stdlib::call entry for net.<method>.
connect
net.connect(...) / net.createConnection(...): build a Socket and start the connection immediately. Returns the socket synchronously; the connect event fires on the main thread once the TCP handshake completes.
constant
Non-function net namespace members: the class constructors, exposed as builtin ctor namespaces so .prototype resolves and new net.X(...) routes through stdlib::construct → net::construct. Stream is a legacy alias of Socket. Reachable via namespace_property → stdlib::constant once the parent adds a "net" => net::constant(name) arm.
construct
stdlib::construct entry for net classes. Parent wires this into stdlib::construct.
create_server
Build a net.Server. An optional connectionListener is stored on the object and invoked (plus connection emitted) for every accepted socket.
instance_call
new_emitter_object
Build a native emitter object (@@native tag + @@on/@@once listener maps) carrying the given extra props. Shared shape with events::new_emitter so 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 by new net.Socket(). connect is called separately.
set_conn_hook
Attach an http-style per-connection hook to a server object (called by http::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 until listen registers the record.
socket_write_id
Write raw bytes to a live socket by id (no-op if it has closed).