https://github.com/tx7do/linuxservertimer
linux game server timer
https://github.com/tx7do/linuxservertimer
asio game-engine libevent libuv linux timer timerfd
Last synced: 23 days ago
JSON representation
linux game server timer
- Host: GitHub
- URL: https://github.com/tx7do/linuxservertimer
- Owner: tx7do
- Created: 2021-11-17T12:42:15.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-18T14:49:49.000Z (almost 4 years ago)
- Last Synced: 2025-01-02T05:32:18.560Z (over 1 year ago)
- Topics: asio, game-engine, libevent, libuv, linux, timer, timerfd
- Language: C++
- Homepage:
- Size: 53.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LinuxServerTimer
本项目主要是为了实验一下使用WSL开发Linux程序。
一开始用的是VS2022,但是用的感觉不是特别好,调试起来不太稳定,因为没有装VA,所以编写代码起来也很难受。
后来转投JetBrian的CLion,编写代码比较舒服,支持Clang-Tidy,代码提示也比较精准。调试起来也很舒服,基本上没有出现什么问题。而且,在使用过程中,我发现它对Doxygen的支持也非常的好。
VS呢,我也用了十多年了,以前用VS+VA,用起来感觉还是很愉快的。但是在JetBrain全家桶面前,我发现它差的有点远。
本项目封装了5种实现方式:
1. 使用sleep实现的低精度低性能定时器;
2. 使用timerfd和epoll实现的高精度高性能定时器;
3. 使用libevent2实现的高精度高性能定时器;
4. 使用boost::asio实现的高精度高性能定时器。
5. 使用libuv实现的高精度高性能定时器。
## 安装依赖库
```bash
# 安装libevent2
sudo apt-get install libevent-dev
# 安装boost
sudo apt-get install libboost-all-dev
# 安装独立版asio
sudo apt-get install -y libasio-dev
# 安装libuv
sudo apt-get install libuv1-dev
```
## 使用方法
```c++
// 创建
auto pITimer = CreateServerTimer(ServerTimerType_Epollfd);
// 注册监听器
pITimer->RegisterListener(this);
// 下一个无限循环的定时器
pITimer->SetTimer(88, 1000);
// 下一个超时一次的定时器
pITimer->SetTimer(99, 1000, false);
// 杀掉一个定时器
pITimer->KillTimer(88);
// 杀掉所有的定时器
pITimer->KillAllTimer();
// 销毁定时器
DestroyServerTimer(pITimer);
```