Files
paseo/packages/client/src/node/buffering.ts
T
Mohamed Boudra 7b4bc87f9a fix(hosts): bound encrypted overload and initial acquisition
Check encrypted wire capacity before the async channel converts a resource limit into a physical connection error. Bound initial routed acquisition with the existing client timeout, then enable reconnect after admission.
2026-10-21 10:33:12 +02:00

26 lines
700 B
TypeScript

/** Counts bytes until the socket's send callback, shared by all links owned by a daemon. */
export class HostTransportBudget {
private used = 0;
constructor(readonly limit = 256 * 1024 * 1024) {}
get bufferedBytes(): number {
return this.used;
}
assertCapacity(bytes: number): void {
if (bytes > this.limit - this.used)
throw Object.assign(new Error("Connected host buffer limit reached"), {
code: "resource_limit",
});
}
reserve(bytes: number): () => void {
this.assertCapacity(bytes);
this.used += bytes;
let released = false;
return () => {
if (!released) {
released = true;
this.used -= bytes;
}
};
}
}