/******************************************************************************** * Copyright (c) 2026 CrossBreeze, EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the MIT License which is available in the project root. * * SPDX-License-Identifier: MIT ********************************************************************************/ import { type Clock } from '@hydranium/protocol'; import { type Channel, Disposable, DisposableCollection, type MessageProvider } from '@theia/core'; import type * as net from 'node:net'; import { type Message, type MessageConnection } from 'vscode-jsonrpc/node'; /** * Relays JSON-RPC messages between a Theia browser-frontend {@link Channel} and * a server's TCP socket — the backend half of a head's transport. The server * speaks vscode-jsonrpc (Content-Length framed) on the socket; the frontend * speaks the same protocol over the channel. This forwarder decodes each side * and re-emits on the other. * * Behaves as `@eclipse-glsp/theia-integration`'s `SocketConnectionForwarder` * does, and both heads use it, except that when the channel closes, the writes * still queued go out before the socket ends. A page going away sends its last * messages and closes its channel in the same tick, and the writer takes * several turns per message, so destroying the socket on the close loses them. */ export declare class SocketChannelForwarder implements Disposable { protected readonly channel: Channel; protected readonly socket: net.Socket; /** Times {@link flushTimeoutMs}. */ protected readonly clock: Clock; protected readonly toDispose: DisposableCollection; /** The last write to the socket; the writer runs its writes one at a time, so this settles last. */ protected lastWrite: Promise; /** * How long {@link endSocket} waits for the queued writes before it destroys * the socket anyway. Without a bound, a server that stops reading holds the * socket open for good, and with it the server's end of the connection. */ protected readonly flushTimeoutMs: number; constructor(channel: Channel, socket: net.Socket, /** Times {@link flushTimeoutMs}. */ clock?: Clock); /** * Dispose `connection`, which destroys the socket, once the writes queued * before the channel closed are out, or {@link flushTimeoutMs} has passed. A * write has settled once the socket handed its bytes to the OS, and * destroying the socket then loses nothing. */ protected endSocket(connection: MessageConnection): Promise; protected decodeChannelMessage(provider: MessageProvider): Message; protected writeToChannel(message: Message): void; dispose(): void; } //# sourceMappingURL=socket-channel-forwarder.d.ts.map