【问题标题】:Libtorrent deprecation warningsLibtorrent 弃用警告
【发布时间】:2022-10-14 00:03:17
【问题描述】:

我正在尝试更新一个使用 libtorrent 1.1.12 的旧项目(所以 libtorrent 1.1.12 到 libtorrent 当前版本)。
当我编译它时,我有这些警告:

warning C4996: 'libtorrent::session::session': was declared deprecated
warning C4996: 'libtorrent::session_handle::set_max_half_open_connections': was declared deprecated
warning C4996: 'libtorrent::session_handle::set_max_uploads': was declared deprecated
warning C4996: 'libtorrent::session_handle::set_max_connections': was declared deprecated
warning C4996: 'libtorrent::session_handle::listen_on': was declared deprecated

所以我的问题是:

  1. 以这种方式初始化“ses”有什么问题?为什么会这样 报告警告?
  2. session_handle 方法警告怎么办?我没有找到任何 v2 中类似的枚举/函数。例如在 settings_pack 枚举 i 没有找到任何关于“half_open_connections”、“max_uploads”的信息 或“最大连接数”。
  3. 关于listen_on,我在文档中看到我可以使用 settings_pack::listen_interfaces。但是,我不再将“ec”传递为 一个参数。那么我该如何检查error_code 是在后面吗?
  4. 在这种情况下,禁用所有警告是否是个好习惯?
    和 “#pragma 警告(禁用:4996)”?
    最后,这是报告警告的项目代码的一部分。
    bool Patcher::Begin()
    {
        ses = new session(                                                      // warning C4996: 'libtorrent::session::session': was declared deprecated
            fingerprint("LT", LIBTORRENT_VERSION_MAJOR, LIBTORRENT_VERSION_MINOR, 0, 0),
            session::add_default_plugins
        );
        
        settings_pack settings;
        settings.set_int(settings_pack::alert_mask, alert_category::status | alert_category::error);
        // ... other settings
    
        ses->set_max_half_open_connections(stConfig.maxHalfOpenConnections);    // warning C4996: 'libtorrent::session_handle::set_max_half_open_connections': was declared deprecated  
        ses->set_max_uploads(stConfig.maxUploadsPerSession);                    // warning C4996: 'libtorrent::session_handle::set_max_uploads': was declared deprecated
        ses->set_max_connections(stConfig.maxConnectionsPerSession);            // warning C4996: 'libtorrent::session_handle::set_max_connections': was declared deprecated
    
        std::pair<int, int> portRange(stConfig.minPort, stConfig.maxPort);
        error_code ec;
    
        ses->listen_on(portRange, ec, nullptr, 0);                              // warning C4996: 'libtorrent::session_handle::listen_on': was declared deprecated
        if (ec.value() != 0)
            // ...
            return false;
    
        ses->apply_settings(settings);
        return true;
    }
    

【问题讨论】:

  • 你必须问图书馆的作者为什么他们选择弃用这些功能。如果我是你,我也会查看他们的文档和变更日志和提交历史,甚至可能是邮件列表档案,以了解原因并找出推荐的替代品。禁用警告肯定是我的最后的采取。

标签: c++ deprecated libtorrent


【解决方案1】:

以这种方式初始化“ses”有什么问题?

询问作者,或者查看他们是否已经在文档中或在引入弃用的提交中解释了它。

为什么会报告警告?

因为作者将其标记为已弃用,出于您应该询问的原因他们关于。

关于什么 ...

如果某些东西被标记为弃用,这意味着其他一些有意识的实体选择了将其标记为已弃用,因为它不应再在新代码中使用。看看他们是否解释了他们的推理或只是问他们。

在这种情况下,禁用所有警告是一个好习惯吗?

禁用所有警告从来都不是好习惯。

弃用警告是故意通知一个或多个接口可能会在未来的更新中被删除。它是一个机会提前遵守新的首选界面。

您可以阅读文档并找出新的首选界面是什么。

例如,如果您正在使用的某些接口在 this commit 中已弃用,它会在提交消息本身中说明哪些重载已弃用,哪些应该优先使用:

弃用 session_flags_t,弃用使用 session_flags_t 支持使用 session_params 的 session_constructors。将会话构造函数定义移动到 cpp 文件中。将会话从类转换为结构

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 2021-07-12
    • 2017-08-22
    • 2011-09-29
    • 2018-09-08
    相关资源
    最近更新 更多