How cloudwego/shmipc-rs works
Shmipc is a Rust library for zero-copy, batched inter-process communication over shared memory, synchronized through Unix-domain or TCP connections. Applications obtain logical streams from a session manager or accept them through a listener; peers negotiate protocol settings, map shared-memory buffers and queues, then exchange stream data and wakeups. The README documents legacy V2/V3 and opt-in V4 modes, including eventfd and polling wakeups. Some subsystem links rely on documented behavior because their implementation was not sampled.
Main entry points: session/mod.rs Session · manager.rs Session manager · initializer/mod.rs Protocol initializer · queue.rs Shared I/O queues
Components 19
Application API
- Listener
src/listener.rs - Connection transport
src/transport.rs
Sessions and Streams
- Session manager
src/session/manager.rs - Session
src/session/mod.rs - Logical stream
src/stream.rs - Stream pool
src/session/pool.rs - Session statistics
src/stats.rs
Protocol Setup
- Protocol setup
src/protocol/mod.rs - Protocol initializer
src/protocol/initializer/mod.rs - Feature negotiation
src/protocol/negotiation.rs - V2 / V3 / V4
src/protocol/initializer
Shared-Memory I/O
- Buffer manager
src/buffer/manager.rs - Buffer slices
src/buffer/slice.rs - Linked buffers
src/buffer/linked.rs - Shared I/O queues
src/queue.rs - Wakeup mechanisms
src/protocol/event.rs
Other components
- Client application
- Server application
- Remote process
Connections 26
- Client application → Session manager: requests streams
- Server application → Listener: accepts streams
- Session manager → Connection transport: connects peer
- Connection transport → Remote process: opens connection
- Listener → Connection transport: accepts connection
- Session manager → Session: creates sessions
- Session manager → Session: rebuilds sessions
- Session manager → Stream pool: obtains streams
- Session → Protocol initializer: initializes protocol
- Protocol initializer → Feature negotiation: negotiates V4
- Feature negotiation → V2 / V3 / V4: selects mode
- Protocol initializer → V2 / V3 / V4: handles legacy setup
- Protocol setup → Buffer manager: creates or maps
- Protocol setup → Shared I/O queues: creates or maps
- Protocol initializer → Buffer manager: maps peer memory
- Protocol initializer → Shared I/O queues: maps peer queue
- Session → Shared I/O queues: dispatches queue events
- Session → Wakeup mechanisms: sends and receives wakeups
- Logical stream → Linked buffers: reads and writes
- Linked buffers → Buffer slices: uses slices
- Buffer slices → Buffer manager: allocates and recycles
- Logical stream → Shared I/O queues: enqueues stream data
- Session → Logical stream: routes incoming streams
- Session → Stream pool: reuses streams
- Session → Session statistics: updates counters
- Feature negotiation → Wakeup mechanisms: selects optional mode