Giter Club home page Giter Club logo

linuxservertimer's Introduction

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实现的高精度高性能定时器。

安装依赖库

# 安装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

使用方法

// 创建
auto pITimer = CreateServerTimer(ServerTimerType_Epollfd);
// 注册监听器
pITimer->RegisterListener(this);
// 下一个无限循环的定时器
pITimer->SetTimer(88, 1000);
// 下一个超时一次的定时器
pITimer->SetTimer(99, 1000, false);
// 杀掉一个定时器
pITimer->KillTimer(88);
// 杀掉所有的定时器
pITimer->KillAllTimer();
// 销毁定时器
DestroyServerTimer(pITimer);

linuxservertimer's People

Contributors

tx7do avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.