Class IpcTransports
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.
| Endpoint | Mechanism |
|---|---|
host:port, tcp:host:port | TCP/IP |
udp:host:port | UDP datagrams with a reliable session |
unix:PATH, unix:@NAME | Unix domain stream socket |
pipe:NAME | Windows named pipe; on POSIX the same as fifo |
fifo:DIR | two POSIX named pipes |
stdio, exec:COMMAND | anonymous pipes of standard input and output |
shm:DIR, mmap:DIR, file:DIR | shared memory, memory-mapped file, file on disk |
signal:DIR | memory-mapped ring announced by OS signals (Windows: events) |
mq:DIR, sysvmq:DIR | POSIX and System V message queues |
mailslot:DIR, copydata:DIR, alpc:DIR | Windows mailslots, WM_COPYDATA, ALPC |
Properties
Kinds
Every built-in endpoint kind, in documentation order.
public static IReadOnlyList<string> Kinds { get; }
Property Value
TraceEnabled
Whether the [ipc] transport log is on.
public static bool TraceEnabled { get; }
Property Value
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
endpointEndpoint
Returns
Connect(string)
Connects to endpoint (see Endpoint).
public static IpcStream Connect(string endpoint)
Parameters
endpointstring
Returns
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
Returns
FromTcpListener(TcpListener)
Wraps an already bound and listening TCP listener.
public static IIpcListener FromTcpListener(TcpListener listener)
Parameters
listenerTcpListener
Returns
FromTcpSocket(Socket)
Wraps a connected TCP socket (Nagle's algorithm is turned off).
public static IpcStream FromTcpSocket(Socket socket)
Parameters
socketSocket
Returns
IsRegistered(string)
Whether kind was added with Register(string, Func<Endpoint, IpcStream>?, Func<Endpoint, IIpcListener>?).
public static bool IsRegistered(string kind)
Parameters
kindstring
Returns
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
endpointEndpoint
Returns
Listen(string)
Listens on endpoint (see Endpoint).
public static IIpcListener Listen(string endpoint)
Parameters
endpointstring
Returns
ListenAll(IEnumerable<string>)
Listens on every endpoint at once; one listener is returned as it is.
public static IIpcListener ListenAll(IEnumerable<string> endpoints)
Parameters
endpointsIEnumerable<string>
Returns
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
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
listenerIIpcListenertargetEndpoint
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
enabledbool
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)