# ipc
**Repository Path**: xsched/ipc
## Basic Information
- **Project Name**: ipc
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-09-28
- **Last Updated**: 2025-09-28
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# C++ IPC Library
## English | [简体中文](docs/README_zh-CN.md)
[](https://github.com/leinfinitr/ipc/blob/main/LICENSE)
## IPC communication library with optional communication methods
This repository implements a C++ IPC library based on the **Linux System V IPC interface** and **Windows communication interface**, encapsulating various IPC mechanisms such as message queues and named pipes. This library aims to simplify communication operations between processes.
### Characteristics
- Supports both Linux and Windows operating systems, as well as multiple compilers such as GCC, MinGW, MSVC, etc.
- When creating a communication node abstraction `IPC::node`, the `IPC::ChannelType` parameter can be used to specify the underlying IPC channel type, such as `messageQueue`, `NamedPipe`, etc.
### Compile and Test
1. Clone the repository: `git clone https://github.com/leinfinitr/ipc.git`
2. Navigate to the project directory: `cd ipc`
3. Initialize submodules: `git submodule update --init --recursive`
4. Compile: `make`
5. After compilation, the following files will be generated in the `output` directory:
1. `ipc-test-xxx` executable test file
2. Static library file `libipc.a` (Linux) or `ipc.lib` (Windows).
- Correctness Test: `/output/bin/ipc-test-correctness`
- Performance Test: run `/output/bin/ ipc-test-performance-server` and `/output/bin/ipc-test-performance-client` sequentially on different terminals.
### Communication method support
- ✅ Realized
- 🔘 Unrealized
- 🚧 Implementing
| Communication method |
OS |
| Windows |
Linux |
| Named pipe |
(Windows NamedPipe) ✅ |
🔘 |
| Message queue |
(Boost Interprocess) ✅ |
(System V IPC) ✅ |
| Shared memory |
🚧 |
🚧 |
### Usage method
#### Introduce IPC library
For projects built using CMake, the IPC library can be introduced through the following methods:
```cmake
set(IPC_LIB_PATH "/path/to/libipc.a")
set(IPC_INCLUDE_DIR "/path/to/ipc/include")
add_library(ipc STATIC IMPORTED)
set_target_properties(ipc PROPERTIES
IMPORTED_LOCATION "${IPC_LIB_PATH}"
INTERFACE_INCLUDE_DIRECTORIES "${IPC_INCLUDE_DIR}"
)
target_link_libraries(your_target ipc)
target_include_directories(your_target PRIVATE ${IPC_INCLUDE_DIR})
```
Alternatively, it can be used directly as a third-party library in CMakeLists.txt:
```cmake
add_subdirectory(ipc EXCLUDE_FROM_ALL)
set(IPC_INCLUDE_DIR "/path/to/ipc/include")
target_link_libraries(your_target ipc)
target_include_directories(your_target PRIVATE ${IPC_INCLUDE_DIR})
```
#### Code Writing
```cpp
#include
// Create two IPC nodes named 'Wow', using NamedPipe or MessageQueue (default) at the bottom
// ipc::node receiver("Wow", ipc::NodeType::Receiver, ipc::ChannelType::NamedPipe);
// ipc::node receiver("Wow", ipc::NodeType::Receiver, ipc::ChannelType::MessageQueue);
ipc::node receiver("Wow", ipc::NodeType::kReceiver);
ipc::node sender("Wow", ipc::NodeType::kSender);
auto rec = receiver.Receive(); // Receive message (will block the process until the message is received)
sender.Send(data, sizeof(data)); // Send a message
```
### Example
Two example programs are provided in the `examples` directory: `sender.cpp` and `receiver.cpp`.
The usage method is as follows:
```bash
cd examples
# Compile
make
# Run receiver
make run_receiver
# Run sender on the new terminal
make run_sender
# At this time, the receiver can receive the message
Received message: Hello, IPC!
```
### Performance
- **Windows**: Intel (R) Core (TM) Ultra 5 225
- **Linux**: Intel (R) Core (TM) Ultra 9 185H
| Communication latency / µs |
Windows |
Linux |
| Message queue |
Named pipe |
cpp-ipc |
Message queue |
cpp-ipc |
| Average |
0.952 |
21.9 |
253.7 |
61.5 |
47.0 |
| Median |
0.900 |
19.7 |
220.3 |
54.0 |
45.9 |
| P95 |
1.10 |
28.5 |
488.4 |
89.1 |
60.1 |
| P99 |
1.20 |
56.5 |
588.9 |
119.5 |
79.1 |