handy:echo server

来源:互联网 发布:windows to go 怎么用 编辑:程序博客网 时间:2024/05/18 05:20

handy:echo

https://github.com/yedf/handy/blob/master/examples/echo.cc

#include <handy/handy.h>using namespace handy;int main(int argc, const char* argv[]) {    EventBase base;    Signal::signal(SIGINT, [&]{ base.exit(); });    TcpServerPtr svr = TcpServer::startServer(&base, "", 99);    exitif(svr == NULL, "start tcp server failed");    svr->onConnRead([](const TcpConnPtr& con) {        con->send(con->getInput());    });    base.loop();}

muudo:echo:

https://github.com/chenshuo/muduo/tree/master/examples/simple/echo

总结:
对比handy的echo和muduo的echo,handy发挥了C++11 lambda的优势,代码更加简洁了。

0 0
原创粉丝点击