https://github.com/mericluc/miniloop
A basic C++ event loop wrapping libevent
https://github.com/mericluc/miniloop
cpp event-loop libevent wrapper
Last synced: 9 months ago
JSON representation
A basic C++ event loop wrapping libevent
- Host: GitHub
- URL: https://github.com/mericluc/miniloop
- Owner: MericLuc
- Created: 2022-07-30T21:03:48.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-10T10:17:44.000Z (over 2 years ago)
- Last Synced: 2025-04-04T16:47:59.569Z (11 months ago)
- Topics: cpp, event-loop, libevent, wrapper
- Language: C++
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# miniLoop
**:star2: A lightweight C++ wrapper around libevent :star2:**
Nothing fancy, miniLoop is a quick and easy-to-use event-loop with basic functionalities :
- Listen on read/write on a file descriptor
- Set timeouts (oneshot and recurrent)
- Register on unix signals
- ... that is pretty much it !
To use it, just start the loop and register your callbacks on the events of your choice.
It wraps [libevent](https://libevent.org/) and is therefore easily extendable to fit your needs.
## How to use
```c++
#include
#include
#include
#include
#define TIMEOUT_HOURLY 3600 * 1000
using namespace loop;
int main(/*int argc, char* argv[]*/) {
// Subscribe to SIGINT signal for example
auto sigintEvt{ Loop::UNIX_SIGNAL(SIGINT) };
sigintEvt.onEvent([](int) { /*graceful_exit(SIGINT);*/ });
// Remember to take a break from screen every hour !
auto takeBreak{ std::make_unique(TIMEOUT_HOURLY) };
takeBreak->onTimeout([](){
std::cout << "Take a break !" << std::endl;
});
// Start the loop
Loop::singleton().run();
return EXIT_SUCCESS;
}
```
## How to install
- Install
```bash
cmake [-S ${path/to/src}] [-DCMAKE_NSTALL_PREFIX=${install/prefix}] .
make
make install
```
- Uninstall
```bash
make uninstall
```
- Configuration options
| name | type | description | default value
| -------------------- | -------- | ---------------------------------- | ---------------
| `BUILD_SHARED_LIBS` | boolean | Build miniLoop as a shared library | ON
| `BUILD_EXAMPLE` | boolean | Also build provided usage example | OFF
## Dependencies
miniLoop depends on :
- [libevent](https://libevent.org/)
- [miniJSON](https://github.com/MericLuc/minijson), which is easy to install from [here](https://github.com/MericLuc/minijson).