C++ 事件循环库 REACT-CPP

码农软件 · 软件分类 · 其他开发相关 · 2019-10-16 20:29:22

软件介绍

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

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

#include <reactcpp.h>
#include <unistd.h>
#include <iostream>
/**
 *  Main application procedure
 *  @return int
 */
int main()
{
    // create an event loop
    React::MainLoop loop;
    // set a timer to stop the application after five seconds
    loop.onTimeout(5.0, []() {
    
        // report that the timer expired
        std::cout << "timer expired" << std::endl;
    
        // stop the application
        exit(0);
    });
    
    // we'd like to be notified when input is available on stdin
    loop.onReadable(STDIN_FILENO, []() -> bool {
    
        // read input
        std::string buffer;
        std::cin >> buffer;
    
        // show what we read
        std::cout << buffer << std::endl;
        
        // return true, so that we also return future read events
        return true;
    });
    // handler when control+c is pressed
    loop.onSignal(SIGINT, []() -> bool {
        
        // report that we got a signal
        std::cout << "control+c detected" << std::endl;
        
        // stop the application
        exit(0);
        
        // although this code is unreachable, we return false because
        // we're no longer interested in future SIGINT signals
        return false;
    });
    // run the event loop
    loop.run();
    // done
    return 0;
}

本文地址:https://codercto.com/soft/d/16910.html

高性能HTML5

高性能HTML5

Jay Bryant、Mike Jones / 奇舞团 / 电子工业出版社 / 2014-5

《高性能html5》为读者讲解了如何用html5 从一开始就设计一个高性能的网站,以及如何对已有网站进行改良,使得它们具备优越的性能。《高性能html5》中总结了许多实践经验、关键技巧,并提供了丰富的示例,作者有意无意地将软件工程以及前端开发技术之道隐藏于朴实的描述中。 通过学习《高性能html5》,读者能够掌握如何创建自己的高性能网站。《高性能html5》适合于想创建自己网站的初学者,同样......一起来看看 《高性能HTML5》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具