Skip to content

Connection

Namespace: E2E.Engine.Protocol

public sealed class Connection : IDisposable

The engine protocol’s base layer, the Language Server Protocol’s base protocol unchanged: JSON-RPC 2.0 messages, each framed by a Content-Length header, over any byte stream. Either side may send requests and notifications; the harness is the client, the engine the server. Nothing here knows an engine method. Requests are answered concurrently; messages are written in the order they are sent, so a notification sent before a response is handled before it. Upstream’s Connection.

Inheritance: object

Implements: IDisposable

View source

Connection(MessageStreams, ConnectionOptions?)

Section titled “Connection(MessageStreams, ConnectionOptions?)”
public Connection(MessageStreams streams, ConnectionOptions? options = null)

Reads and writes <code class=“paramref”>streams</code> until the input ends, fails, or the connection closes.

Parameters

Name Type Description
streams MessageStreams
options ConnectionOptions

public string? Closed { get; }

Why the connection closed, or null while it is open.

Value: string

public void Close(string reason)

Closes the connection: every pending request rejects with <code class=“paramref”>reason</code>.

Parameters

Name Type Description
reason string

public void Dispose()

Closes the connection and stops its readers. .NET-only: a stream is read by a task that must end.

public void Notify(string method, JsonNode? parameters = null)

Sends a notification; dropped once the connection is closed.

Parameters

Name Type Description
method string
parameters JsonNode

OnRequest(string, Func<JsonNode?, Task<JsonNode?>>)

Section titled “OnRequest(string, Func<JsonNode?, Task<JsonNode?>>)”
public void OnRequest(string method, Func<JsonNode?, Task<JsonNode?>> handler)

Registers a request handler after construction, for a method only known later.

Parameters

Name Type Description
method string
handler Func<JsonNode, Task<JsonNode>>

public Task<JsonNode?> RequestAsync(string method, JsonNode? parameters = null)

Sends a request and resolves with its result; throws RpcException.

Parameters

Name Type Description
method string
parameters JsonNode

Returns: Task<JsonNode>