通用C++網絡庫:Fiberized.IO
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(); }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!