c++11 implementation of muduo net lib and muduo asynclogging.
original author github: https://github.com/chenshuo/muduo
因为SimpleMuduo不是稳定版,于是新建了一个仓库维护下这个c++11版。 小bug会在这里修复,SimpleMuduo不再更新,有兴趣的话可以一起维护一下。
#include <async_logging>
#include <muduo_server>
void on_connection(const muduo::TcpConnectionPtr& conn){
LOG_DEBUG << "new conn from " << conn->peerAddress().toIpPort();
}
void on_message(const muduo::TcpConnectionPtr& conn, muduo::Buffer* buffer, ssize_t len){
LOG_DEBUG << "on message : " << len << " bytes " << buffer->peek();
buffer->retrieve(len);
}
int main(){
Logger::setLogLevel(Logger::DEBUG);
muduo::EventLoop loop;
InetAddress localAddr(8080);
muduo::TcpServer tcp_server(&loop, localAddr);
tcp_server.setConnectionCallBack(std::bind(on_connection, std::placeholders::_1));
tcp_server.setMessageCallBack(std::bind(on_message, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
//tcp_server.setCloseCallBack(std::bind(on_close, std::placeholders::_1));
tcp_server.start();
loop.loop();
getchar();
}
-------------------2019/4/30