整理的muduo网络库的c++11版

整理的muduo网络库的c++11版

因为SimpleMuduo不是稳定版,于是新建了一个仓库维护下这个c++11版。
小bug会在这里修复,SimpleMuduo不再更新,有兴趣的话可以一起维护一下。

github : https://github.com/BethlyRoseDaisley/cpp11_muduo
在这里插入图片描述
.
├── bin
│ └── example_server
├── build
├── CMakeLists.txt
├── includes
│ ├── async_logging
│ ├── muduo_logger
│ │ ├── AsyncLogging.hpp
│ │ ├── Condition.hpp
│ │ ├── FileUtil.hpp
│ │ ├── LogFile.hpp
│ │ ├── Logger.hpp
│ │ ├── LogStream.hpp
│ │ ├── ptr_vector.hpp
│ │ ├── scoped_ptr.hpp
│ │ ├── Thread.hpp
│ │ └── TimeStamp.hpp
│ ├── muduo_network
│ │ ├── Acceptor.hpp
│ │ ├── Atomic.hpp
│ │ ├── Buffer.hpp
│ │ ├── CallBacks.hpp
│ │ ├── Channel.hpp
│ │ ├── CurrentThread.hpp
│ │ ├── Endian.hpp
│ │ ├── Epoll.hpp
│ │ ├── EventLoop.hpp
│ │ ├── EventLoopThread.hpp
│ │ ├── EventLoopThreadPool.hpp
│ │ ├── InetAddress.hpp
│ │ ├── Poller.hpp
│ │ ├── Poll.hpp
│ │ ├── SocketHelp.hpp
│ │ ├── Socket.hpp
│ │ ├── TcpConnection.hpp
│ │ ├── TcpServer.hpp
│ │ ├── Timer.hpp
│ │ ├── TimerId.hpp
│ │ └── TimerQueue.hpp
│ └── muduo_server
├── library
│ ├── libasync_logging.a
│ └── libmuduo_server.a
└── sources
├── example
│ ├── example_server.cpp
├── muduo_logger
│ ├── AsyncLogging.cpp
│ ├── FileUtil.cpp
│ ├── LogFile.cpp
│ ├── Logger.cpp
│ ├── LogStream.cpp
│ ├── Thread.cpp
│ └── TimeStamp.cpp
└── muduo_network
├── Acceptor.cpp
├── Buffer.cpp
├── Channel.cpp
├── CurrentThread.cpp
├── Epoll.cpp
├── EventLoop.cpp
├── EventLoopThread.cpp
├── EventLoopThreadPool.cpp
├── InetAddress.cpp
├── Poll.cpp
├── Poller.cpp
├── Socket.cpp
├── SocketHelp.cpp
├── TcpConnection.cpp
├── TcpServer.cpp
├── Timer.cpp
└── TimerQueue.cpp

#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();
}

Alt text

—2019/4/30

添加http处理代码及测试样例 :

在这里插入图片描述

发布了123 篇原创文章 · 获赞 156 · 访问量 28万+

猜你喜欢

转载自blog.csdn.net/qq_17308321/article/details/89684991