Table of Contents

Class IpcTransports

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

Interchangeable inter-process communication transports (issue #140): every IPC mechanism of the operating system as an IpcStream, chosen by an endpoint string, so the mechanism is a decorator layer under the LiNo text and binary protocols.

public static class IpcTransports
Inheritance
IpcTransports
Inherited Members

Remarks

The wire format of every kind is specified in docs/protocol/ipc-transports-v1.md; the Rust and JavaScript implementations follow the same document, so any of them talks to any other.

EndpointMechanism
host:port, tcp:host:portTCP/IP
udp:host:portUDP datagrams with a reliable session
unix:PATH, unix:@NAMEUnix domain stream socket
pipe:NAMEWindows named pipe; on POSIX the same as fifo
fifo:DIRtwo POSIX named pipes
stdio, exec:COMMANDanonymous pipes of standard input and output
shm:DIR, mmap:DIR, file:DIRshared memory, memory-mapped file, file on disk
signal:DIRmemory-mapped ring announced by OS signals (Windows: events)
mq:DIR, sysvmq:DIRPOSIX and System V message queues
mailslot:DIR, copydata:DIR, alpc:DIRWindows mailslots, WM_COPYDATA, ALPC

Properties

Kinds

Every built-in endpoint kind, in documentation order.

public static IReadOnlyList<string> Kinds { get; }

Property Value

IReadOnlyList<string>

TraceEnabled

Whether the [ipc] transport log is on.

public static bool TraceEnabled { get; }

Property Value

bool

Methods

Connect(Endpoint)

Connects to a parsed endpoint.

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The created object is owned by the returned stream or listener, and failure paths dispose it.")]
public static IpcStream Connect(Endpoint endpoint)

Parameters

endpoint Endpoint

Returns

IpcStream

Connect(string)

Connects to endpoint (see Endpoint).

public static IpcStream Connect(string endpoint)

Parameters

endpoint string

Returns

IpcStream

Forward(IpcStream, IpcStream)

Copies both directions between a and b until both ended, passing the end of each direction on with CloseWrite(). Returns the bytes copied from a to b and from b to a. This stacks transports: a relay never parses the protocol.

public static (long Forward, long Backward) Forward(IpcStream a, IpcStream b)

Parameters

a IpcStream
b IpcStream

Returns

(long Forward, long Backward)

FromTcpListener(TcpListener)

Wraps an already bound and listening TCP listener.

public static IIpcListener FromTcpListener(TcpListener listener)

Parameters

listener TcpListener

Returns

IIpcListener

FromTcpSocket(Socket)

Wraps a connected TCP socket (Nagle's algorithm is turned off).

public static IpcStream FromTcpSocket(Socket socket)

Parameters

socket Socket

Returns

IpcStream

IsRegistered(string)

public static bool IsRegistered(string kind)

Parameters

kind string

Returns

bool

Listen(Endpoint)

Listens on a parsed endpoint.

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope", Justification = "The created object is owned by the returned stream or listener, and failure paths dispose it.")]
public static IIpcListener Listen(Endpoint endpoint)

Parameters

endpoint Endpoint

Returns

IIpcListener

Listen(string)

Listens on endpoint (see Endpoint).

public static IIpcListener Listen(string endpoint)

Parameters

endpoint string

Returns

IIpcListener

ListenAll(IEnumerable<string>)

Listens on every endpoint at once; one listener is returned as it is.

public static IIpcListener ListenAll(IEnumerable<string> endpoints)

Parameters

endpoints IEnumerable<string>

Returns

IIpcListener

Register(string, Func<Endpoint, IpcStream>?, Func<Endpoint, IIpcListener>?)

Adds a custom endpoint kind, such as a transport over a device driver. The kind is lowercase ASCII letters, digits and -; built-in kinds cannot be replaced, and registering a kind again replaces the earlier one.

public static void Register(string kind, Func<Endpoint, IpcStream>? connect, Func<Endpoint, IIpcListener>? listen)

Parameters

kind string
connect Func<Endpoint, IpcStream>
listen Func<Endpoint, IIpcListener>

Relay(IIpcListener, Endpoint)

Accepts connections on listener and forwards each one to a new connection to target (see Forward(IpcStream, IpcStream)) until the listener is closed or exhausted, then waits for the forwarded connections to end.

public static void Relay(IIpcListener listener, Endpoint target)

Parameters

listener IIpcListener
target Endpoint

SetTrace(bool)

Turns the [ipc] transport log on standard error on or off. It starts on when the environment variable CLINK_IPC_TRACE is 1.

public static void SetTrace(bool enabled)

Parameters

enabled bool

Supports(string, bool)

Whether this build can connect to (listen false) or listen on the kind here.

public static bool Supports(string kind, bool listen)

Parameters

kind string
listen bool

Returns

bool