6.3.1 代码结构(1)
muduo 的头文件明确分为客户可见和客户不可见两类。以下是安装之后暴露的头文件和库文件。对于使用muduo 库而言,只需要掌握5 个关键类:Buffer、EventLoop、TcpConnection、TcpClient、TcpServer。
- EventLoop、TcpConnection、TcpClient、TcpServer。
- |-- include 头文件
- | \-- muduo
- | |-- base 基础库,同前,略
- | \-- net 网络核心库
- | |-- Buffer.h
- | |-- Callbacks.h
- | |-- Channel.h
- | |-- Endian.h
- | |-- EventLoop.h
- | |-- EventLoopThread.h
- | |-- InetAddress.h
- | |-- TcpClient.h
- | |-- TcpConnection.h
- | |-- TcpServer.h
- | |-- TimerId.h
- | |-- http 以下为网络附属库的头文件
- | | |-- HttpRequest.h
- | | |-- HttpResponse.h
- | | \-- HttpServer.h
- | |-- inspect
- | | |-- Inspector.h
- | | \-- ProcessInspector.h
- | \-- protorpc
- | |-- RpcChannel.h
- | |-- RpcCodec.h
- | \-- RpcServer.h
- \-- lib 静态库文件
- |-- libmuduo_base.a, libmuduo_net.a
- |-- libmuduo_http.a, libmuduo_inspect.a
- \-- libmuduo_protorpc.a
图6-1 是muduo 的网络核心库的头文件包含关系,用户可见的为白底,用户不可见的为灰底。
|
| (点击查看大图)图6-1 |
muduo 头文件中使用了前向声明(forward declaration),大大简化了头文件之间的依赖关系。例如Acceptor.h、Channel.h、Connector.h、TcpConnection.h 都前向声明了EventLoop class,从而避免包含EventLoop.h。另外,TcpClient.h 前向声明了Connectorclass,从而避免将内部类暴露给用户,类似的做法还有TcpServer.h 用到的Acceptor 和EventLoopThreadPool、EventLoop.h 用到的Poller 和TimerQueue、TcpConnection.h 用到的Channel 和Socket 等等。
这里简单介绍各个class 的作用,详细的介绍参见后文。