TcpConnection — 连接生命周期

第 11 课:TcpConnection — 连接生命周期 对应源文件: trantor/net/TcpConnection.h — 公共抽象接口(用户使用) trantor/net/inner/TcpConnectionImpl.h / TcpConnectionImpl.cc — 内部实现 一、设计:接口与实现分离 1 2 3 4 5 6 7 8 9 10 11 12 TcpConnection(纯虚基类) │ 定义公共 API:send/sendFile/shutdown/forceClose/setContext... │ 存储回调:recvMsgCallback_/connectionCallback_/closeCallback_... │ └── TcpConnectionImpl(具体实现) 继承 TcpConnection + NonCopyable + enable_shared_from_this │ ├── Channel(ioChannelPtr_)— fd 事件分发 ├── Socket(socketPtr_) — RAII fd 管理 ├── MsgBuffer readBuffer_ — 接收缓冲区 ├── list<BufferNodePtr> writeBufferList_ — 发送队列 └── TLSProvider(可选) — 透明 TLS 加密层 为什么分离接口和实现? ...

March 22, 2025 · 10 min · 1966 words