Skip to content

Transport

Defined in: packages/net-core/src/transport.ts:56

Abstraction over anything that can carry framed bytes.

Must not assume a Duplex. HTTP/3 runs over QUIC streams, DNS runs over UDP datagrams, and DNS-over-HTTPS runs over the body of another session — none of which are sockets, and all of which reuse the same codecs and correlation logic.

Kept as a bespoke contract rather than a bare ReadableStream/ WritableStream pair. Collapsing to Web Streams costs ~112 ns per received chunk (negligible) but forces either a per-value concatenation (16-233x slower, measured) or the loss of writev batching (3.9x more syscalls, measured) on the send side — and a codec is a symmetric pair that should not need two plumbing vocabularies to follow one round trip.

readonly mode: TransportMode

Defined in: packages/net-core/src/transport.ts:58

Whether bytes arrive as a stream or as discrete messages.

destroy(error?): void

Defined in: packages/net-core/src/transport.ts:113

Tear the transport down immediately, discarding pending I/O.

unknown

Optional cause, propagated to TransportHandlers.error where the transport supports it.

void


end(): Promise<void>

Defined in: packages/net-core/src/transport.ts:105

Half-close the outbound direction and resolve once flushed.

Promise<void>

Resolves when all pending writes have been sent.


pause(): void

Defined in: packages/net-core/src/transport.ts:95

Stop delivering [“data”] until resume.

void


resume(): void

Defined in: packages/net-core/src/transport.ts:98

Resume delivery suspended by pause.

void


optional setWriteCoalescing(enabled): void

Defined in: packages/net-core/src/transport.ts:123

Whether a small write may be held back briefly so it leaves together with later ones — Nagle’s algorithm on TCP. A protocol whose exchanges wait on small messages turns it off; a bulk transfer gains nothing from either.

Omitted by transports that never hold writes back (datagrams, a stream multiplexed over another connection), where there is nothing to turn off.

boolean

void


start(handlers): void

Defined in: packages/net-core/src/transport.ts:67

Begin delivering data to handlers.

Called once by the FrameLink that owns this transport.

TransportHandlers

Callbacks to receive data and lifecycle notifications.

void


stop(): void

Defined in: packages/net-core/src/transport.ts:76

Detach the installed handlers without closing the transport.

Used when handing an already-connected transport to another consumer, as in an HTTP Upgrade. Contrast with destroy, which tears the transport down.

void


write(buffers, signal?): Promise<void>

Defined in: packages/net-core/src/transport.ts:92

Write buffers as a single logical unit and resolve once accepted.

Fragments are written in order and, where the transport supports it, coalesced into one vectored write. In message mode the buffers form exactly one outbound message.

readonly Uint8Array<ArrayBufferLike>[]

Ordered payload fragments.

AbortSignal

Cancels the wait for capacity. Note that bytes already handed to the transport cannot be unsent; aborting rejects the caller but does not retract the write.

Promise<void>

Resolves once the transport has accepted the bytes and any backpressure has cleared.