开发文档

TDLib C++ ClientManager 请求与资源管理

理解 ClientManager 的客户端 ID、非零请求 ID、异步响应与关闭顺序,安全管理多个 TDLib 实例。

GetTGAPI 编辑团队更新于
文档解读核对日期

来源版本 a94b83d67ab4 · TDLib contributors · BSL-1.0

依据官方资料整理,由 GetTGAPI 独立维护。 文档目录与术语表 →

本页内容
  1. 两个 ID 分别关联什么
  2. 并发发送,串行接收与应用
  3. 资源管理建议

两个 ID 分别关联什么

ClientManager::create_client_id 创建实例身份;send 的 request ID 关联一次请求。主动更新的 request ID 为 0,因此业务请求必须使用非零值。收到响应后先判断 client ID,再区分更新与请求结果。

新实例在首次请求前不会发送更新,不能创建后一直等待它自行完成初始化。

并发发送,串行接收与应用

发送可以来自不同线程,receive 不能被多个线程同时调用。返回对象可能因超时为空;非空的更新和响应按接收顺序处理以保持一致性。同步 execute 只适用于文档明确允许的方法。

资源管理建议

用单一所有者管理接收循环和实例关闭,把 UI 操作转换成队列中的请求。关闭时等待相应状态并清理请求等待者,不让旧回调写入已经销毁的页面。日志回调只做受限记录,不能重入 TDLib。

旧 Client 接口仍在固定版本头文件中用于兼容;新开发应先选择一种接口风格并保持一致。完整签名与生命周期注释可从页首固定版本源码查看。

原文许可与归属 · BSL-1.0

TDLib contributors · 完整许可文件

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.