REACT-CPP C++ 事件循环库开源项目

我要开发同款
匿名用户2018年03月05日
121阅读

技术信息

开源地址
https://github.com/CopernicaMarketingSoftware/REACT-CPP
授权协议
Apache-2.0

作品详情

REACT-CPP是利用C++11的lambda表达式在文件描述符或定时器激活的时候进行通知的事件循环库。在它内部实质是对libev库的包装,因此也依赖于该库。

在一个典型的应用程序中,你创建了一个mailoop类的实例,然后注册你想要查看的filedescriptors,注册事件处理程序和计时器:

#iclude <reactcpp.h>#iclude <uistd.h>#iclude <iostream>/** *  Mai applicatio procedure *  @retur it */it mai(){    // create a evet loop    React::MaiLoop loop;    // set a timer to stop the applicatio after five secods    loop.oTimeout(5.0, []() {            // report that the timer expired        std::cout << "timer expired" << std::edl;            // stop the applicatio        exit(0);    });        // we'd like to be otified whe iput is available o stdi    loop.oReadable(STDIN_FILENO, []() -> bool {            // read iput        std::strig buffer;        std::ci >> buffer;            // show what we read        std::cout << buffer << std::edl;                // retur true, so that we also retur future read evets        retur true;    });    // hadler whe cotrol+c is pressed    loop.oSigal(SIGINT, []() -> bool {                // report that we got a sigal        std::cout << "cotrol+c detected" << std::edl;                // stop the applicatio        exit(0);                // although this code is ureachable, we retur false because        // we're o loger iterested i future SIGINT sigals        retur false;    });    // ru the evet loop    loop.ru();    // doe    retur 0;}

功能介绍

REACT-CPP 是利用 C++ 11 的 lambda 表达式在文件描述符或定时器激活的时候进行通知的事件循环库。在它内部实质是对 libev 库的包装,因此也依赖于该库。 在一个典型的应用...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论