Skip to main content

Module ipc

Module ipc 

Source
Expand description

Interchangeable inter-process communication transports (issue #140).

The LiNo text and binary protocols need a reliable, ordered, duplex byte stream. This module turns every IPC mechanism of the operating system into such a stream, an IpcStream, chosen by an endpoint string, so the mechanism is a decorator layer under the protocol: a LinksServer listens and a LinksClient connects through any of them, a server can listen on several at once and forward stacks them.

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/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

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

use link_cli::protocol::ipc::Endpoint;

let endpoint = Endpoint::parse("shm:/tmp/links?capacity=1048576").unwrap();
assert_eq!(endpoint.kind(), "shm");
assert_eq!(endpoint.address(), "/tmp/links");
assert_eq!(Endpoint::parse("127.0.0.1:8080").unwrap().kind(), "tcp");

Structs§

Endpoint
A parsed endpoint: a kind, an address and options.
IpcStream
A cloneable duplex byte stream over any Transport.
MultiListener
Listens on several endpoints at once; see listen_all.

Constants§

KINDS
Every built-in endpoint kind, in documentation order.

Traits§

Listener
Accepts IpcStreams on one endpoint.
Transport
One side of a duplex byte channel.

Functions§

connect
Connects to endpoint (see Endpoint).
connect_endpoint
Connects to a parsed endpoint.
forward
Copies both directions between a and b until both ended, passing the end of each direction on with IpcStream::close_write. Returns the bytes copied from a to b and from b to a.
from_tcp_listener
Wraps an already bound TCP listener.
from_tcp_stream
Wraps a connected TCP stream (Nagle’s algorithm is turned off).
listen
Listens on endpoint (see Endpoint).
listen_all
Listens on every endpoint at once; one listener is returned as it is.
listen_endpoint
Listens on a parsed endpoint.
register
Adds a custom endpoint kind, such as a transport over a device driver.
relay
Accepts connections on listener and forwards each one to a new connection to target (see forward) until the listener is closed or exhausted. Waits for the forwarded connections to end before returning.
set_trace
Turns the [ipc] transport log on standard error on or off. It starts on when the environment variable CLINK_IPC_TRACE is 1.
supports
Whether this build can connect to (listen == false) or listen on the kind on the current platform.
trace_enabled
Whether the [ipc] transport log is on.

Type Aliases§

ConnectFn
Opens an outgoing connection of a custom kind.
ListenFn
Opens a listener of a custom kind.
Waker
Wakes a blocked Listener::accept so it notices that it was closed.