interface NativeRxResult { data: Buffer; msgType: number; actualSize: number; } interface NativeServeResult extends NativeRxResult { correlationId: bigint; } interface NativeRpcBinding { close(): void; call(data: Buffer | Uint8Array, msgType: number): { correlationId: bigint; }; wait(correlationId: bigint, spinThreshold?: number): NativeRxResult | null; commitRx(): void; serve(spinThreshold?: number): NativeServeResult | null; commitServe(): void; reply(correlationId: bigint, data: Buffer | Uint8Array, msgType: number): void; setPollingMode(spinMode: number): void; getState(): number; } /** * Zero-copy read lease on an RPC ring buffer slot. * * Obtain via {@link RpcBus.wait} or {@link RpcBus.serve}. * Call {@link commit} once the payload is consumed, or use `using`. * Failing to commit holds the consumer head indefinitely. */ export declare class RpcRxGuard implements Disposable { #private; /** Message type discriminator set by the sender. */ readonly msgType: number; /** Exact payload size in bytes. */ readonly actualSize: number; /** * Correlation ID of this message. * On the callee side (from {@link RpcBus.serve}), pass unchanged to {@link RpcBus.reply}. */ readonly correlationId: bigint; /** @internal */ constructor(handle: NativeRpcBinding, buffer: Buffer, msgType: number, actualSize: number, correlationId: bigint, isServe: boolean); /** * Returns the zero-copy read window into shared memory. * Invalidated on {@link commit}; any cached reference will throw `TypeError`. * * @throws {Error} If the slot has already been committed. * @throws {PeerDeadError} If the bus has entered TACHYON_STATE_FATAL_ERROR. */ data(): Buffer; /** * Releases the slot and advances the consumer head. No-op if already committed. */ commit(): void; /** Called automatically by the `using` keyword. */ [Symbol.dispose](): void; } /** * Tachyon bidirectional RPC bus backed by two independent SPSC arenas. * * Start the callee first: it owns the UNIX socket and both SHM arenas. * All blocking operations spin then park on a futex; call them from a Worker * thread to avoid saturating the main event loop. * * `using` closes the bus automatically. * * @example * ```ts * // callee (start first) * using bus = RpcBus.listen('/tmp/rpc.sock', 1 << 16, 1 << 16); * const req = bus.serve(); * if (req) { * const cid = req.correlationId; * req.commit(); * bus.reply(cid, Buffer.from('pong'), 2); * } * * // caller * using bus = RpcBus.connect('/tmp/rpc.sock'); * const { correlationId } = bus.call(Buffer.from('ping'), 1); * using resp = bus.wait(correlationId); * ``` */ export declare class RpcBus implements Disposable { #private; private constructor(); /** * Creates two SHM arenas and blocks until a caller connects. * EINTR is retried transparently inside the native layer. * * @param socketPath UDS socket path. Unlinked automatically after handshake. * @param capFwd arena_fwd capacity in bytes (caller to callee). Must be a power of two. * @param capRev arena_rev capacity in bytes (callee to caller). Must be a power of two. */ static listen(socketPath: string, capFwd: number, capRev: number): RpcBus; /** * Connects to an existing SHM arena via the UNIX socket at `socketPath`. * * @throws {AbiMismatchError} If producer and consumer were compiled with incompatible versions. */ static connect(socketPath: string): RpcBus; /** * Controls the polling back-off strategy for both arenas. * Call before the first message. * When `spinMode` is `1`, the producer skips the futex wake check on every flush. * Only use this when both consumer threads are dedicated and never park. */ setPollingMode(spinMode: 0 | 1): void; /** * Copies `data` into arena_fwd and returns the assigned correlation ID. * Blocks if the ring buffer is full. * * @param data Request payload. * @param msgType Application-level message type. * @returns The correlation ID to pass to {@link wait}. */ call(data: Buffer | Uint8Array, msgType: number): bigint; /** * Blocks until the response matching `correlationId` arrives in arena_rev. * Returns `null` on EINTR; caller should retry. * A correlation ID mismatch triggers a fatal error on arena_rev. * * @throws {PeerDeadError} If the bus has entered TACHYON_STATE_FATAL_ERROR. */ wait(correlationId: bigint, spinThreshold?: number): RpcRxGuard | null; /** * Blocks until a request arrives in arena_fwd. * Returns `null` on EINTR; caller should retry. * Commit the returned guard before calling {@link reply} to avoid holding * both arena slots simultaneously. * * @throws {PeerDeadError} If the bus has entered TACHYON_STATE_FATAL_ERROR. */ serve(spinThreshold?: number): RpcRxGuard | null; /** * Copies `data` into arena_rev as a response to `correlationId`. * The guard from {@link serve} must be committed before calling this method. * * @param correlationId Must match the value from the served {@link RpcRxGuard}. Must be > 0. * @param data Response payload. * @param msgType Application-level response type. */ reply(correlationId: bigint, data: Buffer | Uint8Array, msgType: number): void; /** Closes the bus and unmaps both SHM arenas. Safe to call multiple times. */ close(): void; /** Called automatically by the `using` keyword. */ [Symbol.dispose](): void; } export {}; //# sourceMappingURL=rpc.d.ts.map