Skip to content

Architecture

github-actions[bot] edited this page Jul 12, 2026 · 7 revisions

架构总览

分层

wknet::http / websocket / crypto / codec
                    │
             http_api 薄桥
                    │
                 session
          ┌─────────┼─────────┐
       transport  http1/http2  ws
          │             │       │
        net            tls    codec
          └─────────────┴───────┘
                    rtl
  • http_api 只做参数映射、opaque handle 包装和公共生命周期桥接。
  • session 拥有路由、重定向、代理、连接池、异步和 HTTP/WebSocket 编排策略。
  • transport::Transport* 是协议层与真实 I/O 之间的 opaque 服务边界;协议层不直接操作 WSK IRP 或传输布局。
  • net 只提供 WSK 生命周期、解析和字节流能力。
  • tls 只处理握手、记录保护、会话恢复和证书验证。
  • http1http2ws 负责协议状态机,不拥有连接池策略。

请求路径

wknet::http::SendEx
  → http_api 参数映射
  → session::HttpSend
  → HttpRoute / HttpProxy / ConnectionPool
  → HttpH1Dispatch 或 HttpH2Dispatch
  → transport::TransportSend/Receive
  → WSK 或 TLS

WebSocket 连接由 session::WsConnect 编排,HTTP/1.1 Upgrade 与 RFC 8441 共用同一 TLS、连接与取消模型。

所有权边界

  • ConnectionPool.cpp 是池字段的唯一写入者。
  • WskClientWskSocketTransportTlsConnectionHttp2ConnectionPooledConnection 的布局只存在于所属模块私有头。
  • Workspace 与协议聚合缓冲使用堆内存;高频缓冲常驻并复用。
  • src/wknetlib 不使用 .inc 实现分片,每个职责由独立 .cpp 编译。
  • 不存在独立 client 层或第二套网络连接生命周期。

English

Architecture

Layers

wknet::http / websocket / crypto / codec
                    │
           thin http_api bridge
                    │
                 session
          ┌─────────┼─────────┐
       transport  http1/http2  ws
          │             │       │
        net            tls    codec
          └─────────────┴───────┘
                    rtl
  • http_api maps parameters and wraps opaque public handles.
  • session owns routing, redirects, proxy policy, pooling, async work, and HTTP/WebSocket orchestration.
  • opaque transport::Transport* services are the only I/O seam used by protocol layers.
  • net owns WSK lifecycle, resolution, sockets, and byte-stream operations.
  • tls owns handshakes, record protection, resumption, and certificate validation.
  • http1, http2, and ws own protocol state machines, not pooling policy.

Request path

wknet::http::SendEx
  → public argument mapping
  → session::HttpSend
  → HttpRoute / HttpProxy / ConnectionPool
  → HttpH1Dispatch or HttpH2Dispatch
  → transport::TransportSend/Receive
  → WSK or TLS

WebSocket connections are orchestrated by session::WsConnect; HTTP/1.1 Upgrade and RFC 8441 share the same TLS, connection, and cancellation model.

Ownership boundaries

  • ConnectionPool.cpp is the sole writer of pool fields.
  • Layouts for WskClient, WskSocket, Transport, TlsConnection, Http2Connection, and PooledConnection exist only in their owning module's private header.
  • Workspace and aggregate protocol buffers are heap-backed; hot buffers are retained and reused.
  • src/wknetlib contains no .inc implementation fragments; responsibilities compile as independent .cpp units.
  • There is no separate client layer or second network lifecycle.

Clone this wiki locally