IPC Overview
LibIPC provides:
- Type-safe message passing between processes
- Automatic serialization/deserialization
- Request-response and one-way messaging
- File descriptor passing
- Code generation from interface definitions
Architecture
The IPC system consists of several components:IPC Definition Language
IPC interfaces are defined in.ipc files using a simple DSL:
Message Types
Request-Response Messages
Use=> syntax for synchronous request-response:
- Client sends request and blocks waiting for response
- Server processes request and sends response
- Return value delivered to client
One-Way Messages
Use=| syntax for asynchronous one-way messages:
- Client sends message and continues immediately
- Server processes message when received
- No response sent back to client
Code Generation
The IPC compiler (Meta/Lagom/Tools/CodeGenerators/IPCCompiler/) generates C++ code from .ipc files:
- Client Stub
- Server Stub
- Message Structures
Generated
ConnectionToServer class:Serialization
LibIPC automatically serializes and deserializes messages:Supported Types
Primitive Types
Primitive Types
bool: Booleani8,i16,i32,i64: Signed integersu8,u16,u32,u64: Unsigned integersfloat,double: Floating point
String Types
String Types
String: UTF-8 stringByteString: Byte stringStringView: Non-owning view (serialize as String)
Container Types
Container Types
Vector<T>: Dynamic arrayHashMap<K, V>: Hash mapOptional<T>: Maybe type
Custom Types
Custom Types
- Any type with IPC encoding support
- Gfx types (IntRect, IntPoint, Color, etc.)
- File descriptors via
IPC::File - Bitmaps via special
[Bitmap]syntax
Custom Type Encoding
To make a custom type IPC-serializable:File Descriptor Passing
IPC supports passing file descriptors between processes:[File] and [Bitmap] syntax indicates file descriptor transfer:
[File]: Transfers a file descriptor[Bitmap]: Transfers a shared memory region containing a bitmap
Connection Lifecycle
Client Side
Server Side
Common IPC Patterns
Service Discovery
Services listen on well-known socket paths:Multi-Client Services
Services handle multiple clients simultaneously:Request-Response with Timeout
Event Loop Integration
IPC integrates seamlessly with LibCore’s event loop:See Event Loop Documentation for details on the event system.
Security Considerations
Socket Permissions
Socket Permissions
Unix domain sockets use filesystem permissions:
- Sockets in
/tmp/session/%sid/are user-private - Only processes with same session ID can connect
- File permissions prevent unauthorized access
Message Validation
Message Validation
Services must validate all incoming data:
Resource Limits
Resource Limits
- Limit maximum message size
- Limit number of concurrent connections
- Implement rate limiting for expensive operations
- Clean up resources when clients disconnect
Real-World Examples
WindowServer Communication
ImageDecoder Service
ConfigServer
Performance Characteristics
IPC Performance:
- Unix domain sockets are very fast (local communication)
- Zero-copy for file descriptor passing
- Minimal serialization overhead
- Async messages have near-zero latency
- Sync messages have ~µs round-trip time
Debugging IPC
Tools for debugging IPC issues:Further Reading
Event Loop
How IPC integrates with the event system
Services
Learn about system services that use IPC
LibIPC Source
Explore LibIPC implementation
Example .ipc Files
Study real IPC definitions in Userland/Services/
