Table of Contents

Class LinksServer

Namespace
Foundation.Data.Doublets.Cli.Protocol
Assembly
Foundation.Data.Doublets.Cli.dll

A server exposing a links store through the LiNo protocols over any IPC transport (issue #140).

public sealed class LinksServer : IDisposable
Inheritance
LinksServer
Implements
Inherited Members

Remarks

Bind(string, int, LinksServerOptions?) listens on TCP; Listen(string, LinksServerOptions?) takes any Endpoint, such as unix:/tmp/links.sock, pipe:links or shm:/tmp/links, and ListenAll(IEnumerable<string>, LinksServerOptions?) several at once, whose clients share the store and see each other's changes.

Each connection gets its own thread that parses messages and another that writes them; requests are executed one at a time under a lock, so the store needs no thread safety of its own. The protocol is detected per message and the reply uses the same protocol, so text and binary clients can share one server.

A connection may (subscribe: (index source target)) to the links matching a pattern: every later write of another connection that changes such a link is pushed to it as (notify: N) and the changes, in the protocol of the subscription request, until it sends (unsubscribe: N) or hangs up.

Every connection is a LinksSession, with a subject of its own (issue #149).

With Triplets the same requests and pushes are about triplets; see TripletsOperation.

Properties

Endpoint

The endpoints the server listens on, joined by spaces, as clients connect to them.

public string Endpoint { get; }

Property Value

string

Endpoints

Every endpoint the server listens on, in the order given.

public IReadOnlyList<string> Endpoints { get; }

Property Value

IReadOnlyList<string>

LocalEndPoint

The TCP address the server listens on.

public IPEndPoint LocalEndPoint { get; }

Property Value

IPEndPoint

Exceptions

InvalidOperationException

The server listens on no TCP endpoint.

Methods

Bind(string, LinksServerOptions?)

Binds to an address written as host:port.

public static LinksServer Bind(string endPoint, LinksServerOptions? options = null)

Parameters

endPoint string
options LinksServerOptions

Returns

LinksServer

Bind(string, int, LinksServerOptions?)

Binds to host:port (use port 0 for an ephemeral port).

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The server owns the listener.")]
public static LinksServer Bind(string host, int port, LinksServerOptions? options = null)

Parameters

host string
port int
options LinksServerOptions

Returns

LinksServer

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

ErrorDocument(string)

The reply document for a failed request: (error: 'message').

public static IReadOnlyList<Link<string>> ErrorDocument(string message)

Parameters

message string

Returns

IReadOnlyList<Link<string>>

Returns the message of an (error: 'message') reply, or null.

public static string? ErrorMessage(IReadOnlyList<Link<string>> document)

Parameters

document IReadOnlyList<Link<string>>

Returns

string

Executes one request against links.

public static IReadOnlyList<Link<string>> ExecuteRequest(INamedTypesLinks<uint> links, IReadOnlyList<Link<string>> document, bool autoCreateMissingReferences = false)

Parameters

links INamedTypesLinks<uint>
document IReadOnlyList<Link<string>>
autoCreateMissingReferences bool

Returns

IReadOnlyList<Link<string>>

A LinksOperation is one call of the links interface, made by RemoteLinks. Any other non-empty document is a substitution query; the reply holds one (before) (after) line per change, exactly like clink --changes. The empty document asks for every link, one (index: source target) per line. Failures produce an ErrorDocument(string).

Executes the same standard operations and query protocol with selected unsigned addresses.

public static IReadOnlyList<Link<string>> ExecuteRequest<T>(INamedTypesLinks<T> links, IReadOnlyList<Link<string>> document, bool autoCreateMissingReferences = false) where T : struct, IBinaryInteger<T>, IUnsignedNumber<T>, IMinMaxValue<T>

Parameters

links INamedTypesLinks<T>
document IReadOnlyList<Link<string>>
autoCreateMissingReferences bool

Returns

IReadOnlyList<Link<string>>

Type Parameters

T

FromListener(IIpcListener, LinksServerOptions?)

Serves the connections of any listener, such as one of a kind added with Register(string, Func<Endpoint, IpcStream>?, Func<Endpoint, IIpcListener>?); the server then owns it.

public static LinksServer FromListener(IIpcListener listener, LinksServerOptions? options = null)

Parameters

listener IIpcListener
options LinksServerOptions

Returns

LinksServer

Listen(string, LinksServerOptions?)

Listens on an IPC endpoint (see Endpoint), such as 127.0.0.1:0, unix:/tmp/links.sock, pipe:links or shm:/tmp/links.

public static LinksServer Listen(string endpoint, LinksServerOptions? options = null)

Parameters

endpoint string
options LinksServerOptions

Returns

LinksServer

Exceptions

LinoProtocolException

The endpoint is not valid or cannot be listened on, as an Io error.

ListenAll(IEnumerable<string>, LinksServerOptions?)

Listens on every endpoint at once; clients of all of them share the store and see each other's changes.

public static LinksServer ListenAll(IEnumerable<string> endpoints, LinksServerOptions? options = null)

Parameters

endpoints IEnumerable<string>
options LinksServerOptions

Returns

LinksServer

Exceptions

LinoProtocolException

An endpoint is not valid or cannot be listened on, as an Io error.

ParseEndPoint(string)

Splits host:port (or [ipv6]:port) into its parts.

public static (string Host, int Port) ParseEndPoint(string endPoint)

Parameters

endPoint string

Returns

(string Host, int Port)

QueryDocument(string)

An opt-in envelope preserving original query reference kinds across every codec.

public static IReadOnlyList<Link<string>> QueryDocument(string query)

Parameters

query string

Returns

IReadOnlyList<Link<string>>

Serves links until Shutdown() is called, or until the listener can accept no more connections (a stdio listener once its only connection ended).

public void Serve(INamedTypesLinks<uint> links)

Parameters

links INamedTypesLinks<uint>

Serves the selected unsigned address type through the same protocols.

public void Serve<T>(INamedTypesLinks<T> links) where T : struct, IBinaryInteger<T>, IUnsignedNumber<T>, IMinMaxValue<T>

Parameters

links INamedTypesLinks<T>

Type Parameters

T

Shutdown()

Stops Serve(INamedTypesLinks<uint>) and closes every open connection.

public void Shutdown()