muduo编程风格
面向对象风格: 用一个EchoServer 继承 TcpServer这个抽象类,再去实现各自的三个接口函数
基于对象风格: 用一个EchoServer 包含 一个TcpServer这个具体类对象, 在构造函数中用boost::bind来注册三个成员函数
文件描述符
项目中使用的所有socketfd
Server的函数中定义的listenfd
传递给mainloop的Channel
Server的函数中定义的connfd
传递给给subloop的Channel
项目中使用的所有eventfd
EventLoop中的wakeupfd
Epoll中的epollfd
Channel中的fd既有可能是socketfd也有可能是eventfd
网络结构
EventLoop
wakeupChannel_的作用
mainloop会把subloop要执行的事件通过queueInLoop()函数放入subloop的pendingFunctors_数组中,然后向wakefd_中写数据的方式唤醒对应的wakeupChannel_
subloop的loop()函数中把执行pendingFunctors_数组中的函数这个行为的doPendingFunctors()函数绑定在wakeupChannel_执行的事件中,同时把wakeupChannel_放入poller_中,在loop()函数的while循环中会不断调用poller_的poll()函数,因为queueInLoop唤醒了wakeupChannel_,所以poll()函数得到的就绪事件中就会包含wakeupChannel_对应的事件,接着就会调用wakeupChannel_的handleEvent()函数执行事件了。
所以wakeupChannel_中的就是mainLoop想要subLoop做的事件,通过上述过程subLoop让进行执行
Channel
不同Channel处理的读回调函数
subloop的connChannel
SSL握手
Http_conn的parse()
mainloop的serverChannel
Server的handleConn()
subloop的wakeupChannel
doPendingFunctors()
connChannel处理的不同写回调函数
Http_conn进入parseError
writeHandler绑定Http_conn::send()
Http_conn进入parseSuccess
writeHandler绑定Http_conn::handleError()
Epoll
日志
HTTP
处理HTTP连接的状态机流程
线程池
Thread
ThreadFunc绑定的函数的类别
EventLoopThread的loop()
AsyncLogging的threadFunc()
C++特性
智能指针的使用
unique_ptr
Thread
每个EventLoop对象唯一拥有Thread
EventLoopThreadPool
每个Server对象唯一拥有EventLoopThreadPool
AsyncLogging
每个Logger对象唯一拥有AsyncLogging
FileUtil
每个LogFile对象唯一拥有FileUtil
shared_ptr
Epoll
每个EventLoop中拥有一个Epoll的共享指针对象
Channel
以下4个类可能会共享同一个Channel:
每个Epoll中有一个unordered_map中装载event_fd和Channel共享指针对象的映射
每个EventLoop(subloop)中有一个Channel的共享指针对象
每个TimerNode中有一个Channel的共享指针对象
每个Http_conn中有一个Channel的共享指针对象
以下2个类可能会共享同一个Channel:
每个Server中有一个Channel的共享指针对象
每个Server中的EventLoop(mainloop)共享指针对象中有一个Channel的共享指针对象
EventLoop
IOThreadPool_ 调用 getNextLoop() 得到的 EventLoop 会使用到 connChannel 的构造函数的参数中去
因此以下2个类可能会共享同一个EventLoop:
每个EventLoopThread中有一个EventLoop共享指针对象
每个Channel中有一个EventLoop的共享指针对象
EventLoopThread
每个EventLoopThreadPool中有一个数组装载EventLoopThread的共享指针对象
Http_conn
每个Server中有一个unordered_map装载connfd和Http_conn共享指针对象的映射