Interface: Transport
Pure callback-bag transport abstraction.
Each onXxx registration is set-once: calling onData(fn) a second time
replaces the first handler. This prevents listener leaks across reconnect cycles
where Connection re-registers handlers on a fresh Transport.
Example
function writeAll(t: Transport, chunks: Buffer[]): void {
for (const chunk of chunks) t.write(chunk);
}
Methods
close()
close():
void
Initiate graceful close of the underlying transport.
The registered onClose handler fires once the socket is fully closed.
Returns
void
destroy()
destroy(
reason?):void
Abruptly destroy the transport, discarding any pending writes.
Fires onError(reason) (if provided) then onClose.
Parameters
reason?
Error
Optional error describing why the transport was destroyed.
Returns
void
onClose()
onClose(
fn):void
Register the close handler. Called once when the underlying socket is fully closed. Replaces any previously registered handler (set-once semantics).
Parameters
fn
() => void
Returns
void
onConnect()
onConnect(
fn):void
Register the connect handler. Called once after TCP (or TLS) handshake completes. Replaces any previously registered handler (set-once semantics).
Parameters
fn
() => void
Returns
void
onData()
onData(
fn):void
Register the data handler. Called synchronously for each received chunk. Replaces any previously registered handler (set-once semantics).
Parameters
fn
(chunk) => void
Called with each raw chunk as it arrives from the OS.
Returns
void
onError()
onError(
fn):void
Register the error handler. Called for socket-level errors (ECONNRESET, ETIMEDOUT, etc.). Replaces any previously registered handler (set-once semantics).
Parameters
fn
(err) => void
Receives the underlying OS or TLS error.
Returns
void
write()
write(
buf):boolean
Write buf to the underlying transport.
Parameters
buf
Buffer
Returns
boolean
true if the bytes were flushed to the kernel immediately;
false if the write was buffered (backpressure, caller should pause sending
until the onDrain event fires at the Connection layer).