Coder Social home page Coder Social logo

ec's Introduction

ec是基于libevet的C++11封装。

联系方式

QQ: 405026523

邮件:[email protected]

欢迎大家恶贡献代码!

编译

依赖条件

  • C++版本需要支持C++11
  • libevent需要2.0以上版本

编译方法

没有提供CMake和安装脚本。

编译成动态链接库:

make -f makefile

编译测试用例:

make -f ExampleMakefile

整体架构

输入图片说明

ec的的命名空间为ec,主要包含如下几个类:

  • Loop 事件循环和线程的结合,对libevent中struct event_base的封装;
  • Timer 定时器类,依赖Loop,支持按周期定时、延迟定时、永久定时;
  • TcpServer TCP服务器类,线程安全,可设置IO线程数量;
  • HttpServer HTTP服务器类,仅实现了部分简单功能;

Loop

Loop封装了事件循环和线程管理,建议一个线程只拥有一个Loop; Timer、TcpSocket必需关联到Loop,相应行为都将在Loop的线程触发。

#include "ec/loop.h"
int main(int argc, char *argv[])
{
    ec::Loop loop;
    loop.start(false); //false当前线程阻塞,true则以新线程运行
    loop.wait(); //等待线程结束,仅对以新线程运行方式有效
}

TcpServer

多线程的TCP服务器,可设置IO线程的数量

测试示例

先用make -f ExampleMakefile编译生成test后:

./test timer

./test timer 测试定时器用法。

./test tcp 测试TCP的用法。

./test http 将启动HTTP服务器,访问http://127.0.0.1:4567/。

测试代码

test.cpp 为主入口,具体功能实现在example目录中

定时器示例

void timerExample();

TCP示例

void tcpExample();

HTTP示例

void httpExample();

ec's People

Contributors

havesnag avatar

Stargazers

guowendev avatar deyili avatar JaredYeah avatar Mensong avatar chet avatar

Watchers

James Cloos avatar  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.