Coder Social home page Coder Social logo

muduo_cpp11's Introduction

C++11 Muduo

流程图

开发环境

  • linux kernel version 4.4.0 (ubuntu 16.04 Server)
  • gcc version 5.4.0
  • cmake version 3.5.1

项目编译执行./build.sh即可,测试用例进入example/文件夹,make即可生成服务器测试用例

功能介绍

头文件生成至目录/usr/include/mymuduo/.so库文件生成至目录/usr/lib/

  1. EventLoop.*Channel.*Poller.*EPollPoller.*等主要用于事件轮询检测,并实现了事件分发处理的底层实现方法。EventLoop负责轮询执行Poller,要进行读、写、错误、关闭等事件时需执行哪些回调函数,均绑定至Channel中,只需从中调用即可,事件发生后进行相应的回调处理即可
  2. Thread.*EventLoopThread.*EventLoopThreadPool.*等将线程和EventLoop事件轮询绑定在一起,实现真正意义上的one loop per thread
  3. TcpServer.*TcpConnection.*Acceptor.*Socket.*等是mainloop对网络连接的响应并轮询分发至各个subloop的实现,其中注册大量回调函数
  4. Buffer.*muduo网络库自行设计的自动扩容的缓冲区,保证数据有序性到达

技术亮点

  1. EventLoop中使用了eventfd来调用wakeup(),让mainloop唤醒subloopepoll_wait阻塞
  2. EventLoop中注册回调cbpendingFunctors_,并在doPendingFunctors中通过swap()的方式,快速换出注册的回调,只在swap()时加锁,减少代码临界区长度,提升效率。(若不通过swap()的方式去处理,而是加锁执行pendingFunctors中的回调,然后解锁,会出现什么问题呢?1. 临界区过大,锁降低了服务器响应效率 2. 若执行的回调中执行queueInLoop需要抢占锁时,会发生死锁)
  3. Logger可以设置日志等级,调试代码时可以开启DEBUG打印日志;若启动服务器,由于日志会影响服务器性能,可适当关闭DEBUG相关日志输出
  4. Thread中通过C++lambda表达式以及信号量机制保证线程创建时的有序性,只有当线程获取到了其自己的tid后,才算启动线程完毕
  5. TcpConnection继承自enable_shared_from_thisTcpConnection对象可以调用shared_from_this()方法给其内部回调函数,相当于创建了一个带引用计数的shared_ptr,可参考链接 link,同时muduo通过tie()方式解决了TcpConnection对象生命周期先于Channel结束的情况
  6. muduo采用Reactor模型和多线程结合的方式,实现了高并发非阻塞网络库

视频介绍

持续更新..

muduo_cpp11's People

Contributors

s1mplebug avatar truemars avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.