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.
| 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/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 |
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. - Multi
Listener - Listens on several endpoints at once; see
listen_all.
Constants§
- KINDS
- Every built-in endpoint kind, in documentation order.
Traits§
Functions§
- connect
- Connects to
endpoint(seeEndpoint). - connect_
endpoint - Connects to a parsed endpoint.
- forward
- Copies both directions between
aandbuntil both ended, passing the end of each direction on withIpcStream::close_write. Returns the bytes copied fromatoband frombtoa. - 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(seeEndpoint). - 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
listenerand forwards each one to a new connection totarget(seeforward) 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 variableCLINK_IPC_TRACEis1. - 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§
- Connect
Fn - Opens an outgoing connection of a custom kind.
- Listen
Fn - Opens a listener of a custom kind.
- Waker
- Wakes a blocked
Listener::acceptso it notices that it was closed.