A simple, line-based asynchronous message passing library built on top of my ep_engine (an epoll-based event engine).
This library provides a way to implement lightweight asynchronous server–client model using line-based messages.
It offers:
- A non-blocking, epoll-based I/O model
- Asynchronous message handling
-
Line-based message protocol
Messages are considered complete when a newline (\n) is received. -
Asynchronous server–client model
Uses an event-driven architecture built on ep_engine. -
Callback-driven message handling
mp_serveraccepts a user-provided request handler callback.- The callback is triggered whenever the server receives a message from a client.
- The handler can send a reply message back to that client.
mp_clientaccepts a user-provided on_reply callback.- The client can send requests to the server.
- The
on_replycallback is called asynchronously when the client receives a reply.
-
Notes
- This project is mainly for personal use, not for production codes.
Thus, the code may lack thorough testing, so please use it with caution. - This project uses my ep_engine library. The CMake file will automatically fetch the project internally
- This library depends on pthread, so you must link with -lpthread
- This project is mainly for personal use, not for production codes.
Follow these steps to build and install the library:
# 1. Clone the repository
git clone https://github.com/wjnlim/msg_pass.git
# 2. Create a build directory
mkdir msg_pass/build
cd msg_pass/build
# 3. Configure with CMake
cmake -DCMAKE_INSTALL_PREFIX=<your install directory> ..
# 4. Build and install the library
cmake --build . --target installRefer to the demo program in the repository for example usage.
To compile them:
# hello_server
gcc hello_server.c -o hello_server -I <your install directory>/include/ <your install directory>/lib/libmsg_pass.a -lpthread
# hello_client
gcc hello_client.c -o hello_client -I <your install directory>/include/ <your install directory>/lib/libmsg_pass.a -lpthreadTo run them:
# demo server
./hello_server
# demon client
./hello_client <server ip> <client name> <use_threadpool> <number_of_requests>To compile your program using this library (note that the pthread library must be linked with also):
gcc your_prog.c -o your_prog -I <your install directory>/include \
<your install directory>/lib/libep_engine.a -lpthread