通用C++网络库:Fiberized.IO

jopen 9年前

Fiberized.IO是一个快速和简单,基于Fiber和Async I/O的通用C++网络库。

  • Fast
    Asynchronous I/O under the hood for maximum speed and throughtput.
  • Simple
    Fiber based programming model for concise and intuitive development.
  • No compromises
    Standard C++ thread and iostream compatible API, old-fashion programs just work more efficiently.

在上层,Fiberized.IO提供一个兼容C++11 thread和iostream的“阻塞式”API;在底层,Fiberized.IO通过将阻塞式IO映射为异步IO和kernel/userland 混合调度的Fiber,在最大化程序的运行效率的同时保持用户的程序清晰简单易于理解。

除基本的功能之外,Fiberized.IO还包含了一个完整的HTTP服务框架,一个Redis客户端,以及Apache Thrift的支持,未来计划支持常见的数据库如MySQL和MongoDB等。

The echo server example

#include <fibio/fiberize.hpp>  #include <fibio/iostream.hpp>    using namespace fibio;    int fibio::main(int argc, char *argv[]) {      return tcp_listener(7)([](tcp_stream &s){          s << s.rdbuf();      }).value();  }

一个 HTTP 服务器示例代码:

#include <fibio/fiberize.hpp>  #include <fibio/http_server.hpp>     using namespace fibio::http;     bool handler(server::request &req,               server::response &resp)  {      resp.body_stream() << "<HTML><BODY><H1>"                         << req.params["p"]                         << "</H1></BODY></HTML>"                         << std::endl;      return true;  }     int fibio::main(int argc, char *argv[]) {      server svr(server::settings{          route(path_("/*p") >> handler),          23456,      });      svr.start();      svr.join();  }

项目主页:http://www.open-open.com/lib/view/home/1416879982416